@@ -20,12 +20,12 @@ function Select-YamlRemovalTarget {
2020 foreach ($target in $Targets ) {
2121 Add-YamlRemovalWork - State $State - Operation ' target coalescing' - Node $target.Node
2222 if ($coalesced.ContainsKey ($target.Key )) {
23- $coalesced [$target.Key ].AncestorSets .Add([string []] $target.Ancestors )
23+ $coalesced [$target.Key ].PathSets .Add([string []] $target.Path )
2424 continue
2525 }
2626
27- $ancestorSets = [System.Collections.Generic.List [object ]]::new()
28- $ancestorSets .Add ([string []] $target.Ancestors )
27+ $pathSets = [System.Collections.Generic.List [object ]]::new()
28+ $pathSets .Add ([string []] $target.Path )
2929 $coalesced [$target.Key ] = [pscustomobject ]@ {
3030 Key = $target.Key
3131 Kind = $target.Kind
@@ -34,28 +34,59 @@ function Select-YamlRemovalTarget {
3434 Edge = $target.Edge
3535 Node = $target.Node
3636 Depth = $target.Depth
37- AncestorSets = $ancestorSets
37+ PathSets = $pathSets
3838 Pointer = $target.Pointer
3939 DocumentIndex = $target.DocumentIndex
4040 }
4141 }
4242
43- $selectedKeys = [System.Collections.Generic.HashSet [string ]]::new(
44- [System.StringComparer ]::Ordinal
45- )
46- foreach ($key in $coalesced.Keys ) {
47- [void ] $selectedKeys.Add ($key )
43+ $pathRoot = [pscustomobject ]@ {
44+ Children = [System.Collections.Generic.Dictionary [string , object ]]::new(
45+ [System.StringComparer ]::Ordinal
46+ )
47+ TargetKeys = [System.Collections.Generic.HashSet [string ]]::new(
48+ [System.StringComparer ]::Ordinal
49+ )
50+ }
51+ foreach ($target in $coalesced.Values ) {
52+ foreach ($path in $target.PathSets ) {
53+ $pathNode = $pathRoot
54+ foreach ($edgeKey in $path ) {
55+ Add-YamlRemovalWork - State $State - Operation ' target path indexing' `
56+ - Node $target.Node
57+ if (-not $pathNode.Children.ContainsKey ($edgeKey )) {
58+ $pathNode.Children [$edgeKey ] = [pscustomobject ]@ {
59+ Children = [System.Collections.Generic.Dictionary [string , object ]]::new(
60+ [System.StringComparer ]::Ordinal
61+ )
62+ TargetKeys = [System.Collections.Generic.HashSet [string ]]::new(
63+ [System.StringComparer ]::Ordinal
64+ )
65+ }
66+ }
67+ $pathNode = $pathNode.Children [$edgeKey ]
68+ }
69+ [void ] $pathNode.TargetKeys.Add ($target.Key )
70+ }
4871 }
4972
5073 $survivors = [System.Collections.Generic.List [object ]]::new()
5174 foreach ($candidate in $coalesced.Values ) {
5275 $allRequestsSubsumed = $true
53- foreach ($ancestorSet in $candidate.AncestorSets ) {
76+ foreach ($path in $candidate.PathSets ) {
5477 $requestSubsumed = $false
55- foreach ($ancestorKey in $ancestorSet ) {
56- Add-YamlRemovalWork - State $State - Operation ' ancestor coalescing' `
78+ $pathNode = $pathRoot
79+ for ($pathIndex = 0 ; $pathIndex -lt $path.Count - 1 ; $pathIndex ++ ) {
80+ Add-YamlRemovalWork - State $State - Operation ' target path ancestry' `
5781 - Node $candidate.Node
58- if ($selectedKeys.Contains ($ancestorKey )) {
82+ $edgeKey = $path [$pathIndex ]
83+ if (-not $pathNode.Children.ContainsKey ($edgeKey )) {
84+ break
85+ }
86+ $pathNode = $pathNode.Children [$edgeKey ]
87+ if ($pathNode.TargetKeys.Count -gt 1 -or
88+ ($pathNode.TargetKeys.Count -eq 1 -and
89+ -not $pathNode.TargetKeys.Contains ($candidate.Key ))) {
5990 $requestSubsumed = $true
6091 break
6192 }
0 commit comments