Adding DFS Patch from Tomasz Skutnik

Here's patch against HEAD version of DFS algorithm in
jakarta-commons-sandbox/graph2 package - it uses less memory, which is
important for very large graphs (as in my case). Additionally DFS now
can use lazy graph implementations without causing full, in-memory
vertex retrieval on search initialization.


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/sandbox/graph2/trunk@144643 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
ddp committed 2003-07-23 14:07:18 +00:00
1 parent fa74913bae
commit 67d62e0664
1 file changed
+6 -16
@@ -94,7 +94,8 @@ public class DFS
*/
public String getColor(Vertex v)
{
return (String) colors.get(v);
String color = (String)colors.get(v);
return color != null ? color : WHITE;
}
@@ -109,7 +110,7 @@ public class DFS
Vertex v = graph.getTarget(e);
if (colors.get(v) == WHITE)
if (getColor(v) == WHITE)
{
visitVertex(graph, v, visitor);
}
@@ -124,7 +125,6 @@ public class DFS
Vertex v,
Visitor visitor)
{
colors.remove(v);
colors.put(v, GRAY);
visitor.discoverVertex(v);
@@ -138,7 +138,6 @@ public class DFS
visitor.finishVertex(v);
colors.remove(v);
colors.put(v, BLACK);
}
@@ -149,12 +148,7 @@ public class DFS
Vertex root,
Visitor visitor)
{
Iterator vertices = graph.getVertices().iterator();
while (vertices.hasNext())
{
colors.put(vertices.next(), WHITE);
}
colors.clear();
visitor.discoverGraph(graph);
visitVertex(graph, root, visitor);
@@ -166,14 +160,10 @@ public class DFS
* visit - Visits all nodes in the graph.
*/
public void visit( DirectedGraph graph, Visitor visitor ) {
Iterator vertices = graph.getVertices().iterator();
while (vertices.hasNext()) {
colors.put( vertices.next(), WHITE );
}
colors.clear();
visitor.discoverGraph( graph );
vertices = graph.getVertices().iterator();
Iterator vertices = graph.getVertices().iterator();
while (vertices.hasNext()) {
Vertex v = (Vertex) vertices.next();