Skip to content

Commit 8d4b73a

Browse files
committed
Fixed gap algo
1 parent 99aeaa6 commit 8d4b73a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

CSharpCodeAnalyst/Exploration/CodeGraphExplorer.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,10 @@ public SearchResult FindGapsInHierarchy(HashSet<string> knownIds)
518518
}
519519

520520

521-
// Alternative implementation
522521
private HashSet<string> FillGapsInHierarchy(HashSet<string> knownIds)
523522
{
524523
var added = new HashSet<string>();
524+
525525
if (_codeGraph is null)
526526
{
527527
return added;
@@ -534,17 +534,19 @@ private HashSet<string> FillGapsInHierarchy(HashSet<string> knownIds)
534534
continue; // Skip invalid Id
535535
}
536536

537-
// Walk up until we reach a parent already known or run out.
538-
while (current.Parent is not null && !knownIds.Contains(current.Parent.Id))
537+
var fromRootToCurrent = current.GetPathToRoot(false).ToList();
538+
var addFromHere = false;
539+
foreach (var parent in fromRootToCurrent)
539540
{
540-
if (added.Add(current.Parent.Id))
541+
if (knownIds.Contains(parent.Id))
541542
{
542-
current = current.Parent;
543+
// Found a parent, all elements from here down to current need to be present.
544+
addFromHere = true;
543545
}
544-
else
546+
547+
if (addFromHere)
545548
{
546-
// Already added
547-
current = current.Parent;
549+
added.Add(parent.Id);
548550
}
549551
}
550552
}

0 commit comments

Comments
 (0)