Closed haved closed 1 month ago
The change you suggest is what I did first, but I still need to pop the element. One alternative would be to break it into if/elseif/else, which might be nicer.
Regarding unit testing it, it can be done with a custom callback, that checks that each node is only queried about its successor twice. I can absolutely do that
I added a test and changed the code to avoid continue
This does not affect correctness, but should boost performance by avoiding unnecessary visits of nodes that are already parts of finished SCCs.
When implementing DFS using a stack, I had forgotten that the same node can be added multiple times before it actually gets visited. In a graph like
Visiting node A will push B and C. Since we then visit C first, it will also have to push B to process B before C can be popped. The edge
A->B
should then be ignored when popping B the second time.