# HG changeset patch # User Aziz K?ksal # Date 1201377567 -3600 # Node ID 4c0ea78a7f8b33d171e5a415f48178282016f664 # Parent 1564e41f454eaf52bbda7964a1a332d6aa77a94a Fixed cycle detection algorithm. diff -r 1564e41f454e -r 4c0ea78a7f8b trunk/src/cmd/ImportGraph.d --- a/trunk/src/cmd/ImportGraph.d Sat Jan 26 20:08:03 2008 +0100 +++ b/trunk/src/cmd/ImportGraph.d Sat Jan 26 20:59:27 2008 +0100 @@ -71,17 +71,23 @@ void detectCycles() { // Cycles could also be detected in the GraphBuilder, // but having the code here makes things much clearer. - void visit(Vertex vertex) + bool visit(Vertex vertex) { if (vertex.status == Vertex.Status.Visiting) { vertex.isCyclic = true; - return; + return true; } + if (vertex.status == Vertex.Status.Visited) + return false; + // Flag as visiting. vertex.status = Vertex.Status.Visiting; + // Visit successors. foreach (outVertex; vertex.outgoing) - visit(outVertex); + vertex.isCyclic |= visit(outVertex); + // Flag as visited. vertex.status = Vertex.Status.Visited; + return false; } // Start visiting vertices. visit(vertices[0]);