Skip to content

Commit 9cfbc90

Browse files
committed
Process TODO comment
1 parent 64dab92 commit 9cfbc90

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Code/Graph+Algorithms/Graph+MinimumEquivalentGraph.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public extension Graph
88
🛑 This only works on acyclic graphs and might even hang or crash on cyclic ones!
99
*/
1010
func makeMinimumEquivalentGraph() -> Graph<NodeID, NodeValue>
11-
{
11+
{
1212
var minimumEquivalentGraph = self
1313
minimumEquivalentGraph.removeEdges(with: findTransitiveEdges())
1414
return minimumEquivalentGraph
@@ -27,7 +27,6 @@ public extension Graph
2727

2828
var consideredAncestorsHash = [NodeID: NodeIDs]()
2929

30-
// TODO: keep track of visited nodes within each traversal from a node and ignore already visited nodes so we can't get hung up in cycles. be aware that iterating through only the sources in this loop will also not work when graphs are potentially cyclic or even exclusively made of cycles (i.e. have no sources)!
3130
for sourceNode in sources
3231
{
3332
idOfTransitiveEdges += findTransitiveEdges(around: sourceNode,
@@ -42,6 +41,8 @@ public extension Graph
4241
reachedAncestors: NodeIDs,
4342
consideredAncestorsHash: inout [NodeID: NodeIDs]) -> EdgeIDs
4443
{
44+
// to make this not hang in cycles it might be enough to just ensure that node is not in reachedAncestors ...
45+
4546
let consideredAncestors = consideredAncestorsHash[node.id, default: NodeIDs()]
4647
let ancestorsToConsider = reachedAncestors - consideredAncestors
4748

0 commit comments

Comments
 (0)