Last active
September 11, 2016 20:38
-
-
Save csullivan/e704a69223ab56c502a8c87c6fc6c0f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
S - Set of all nodes with no inbound connections (NodeType::Input) | |
-- Enumerating all paths | |
paths = {} | |
for each node n in S do | |
visit(n,{}) | |
function visit(node n, list l) | |
if n is not in l then | |
l.insert(n) | |
if n has no outbound connections then | |
paths.insert(l) | |
else | |
for each node m with an edge from n to m do | |
visit(m,l) | |
else | |
l.insert(n) | |
paths.insert(l) | |
l.remove_last_inserted() | |
-- any path in paths which has repeated nodes, has a cycle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think we can bail out early if we find a connection. It would also avoid having to have the std::set.