From 254ee6f47eebfc00462c10756a92066e82cc1a96 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 21 Jun 2011 15:46:02 +0200 Subject: Initial commit --- .../c2kernel/graph/traversal/GraphTraversal.java | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 source/com/c2kernel/graph/traversal/GraphTraversal.java (limited to 'source/com/c2kernel/graph/traversal/GraphTraversal.java') diff --git a/source/com/c2kernel/graph/traversal/GraphTraversal.java b/source/com/c2kernel/graph/traversal/GraphTraversal.java new file mode 100755 index 0000000..abf30f7 --- /dev/null +++ b/source/com/c2kernel/graph/traversal/GraphTraversal.java @@ -0,0 +1,85 @@ +package com.c2kernel.graph.traversal; + + +import java.util.Vector; + +import com.c2kernel.graph.model.GraphModel; +import com.c2kernel.graph.model.Vertex; + + +public class GraphTraversal +{ + public static final int kUp = 1; + public static final int kDown = 2; + + + private GraphTraversal() + { + } + + + public static Vertex[] getTraversal(GraphModel graphModel, Vertex startVertex, int direction, boolean ignoreBackLinks) + { + Vector path = new Vector(10, 10); + + graphModel.clearTags(startVertex); + visitVertex(startVertex, graphModel, path, direction, startVertex, ignoreBackLinks); + + return vectorToVertexArray(path); + } + + + private static void visitVertex(Vertex vertex, GraphModel graphModel, Vector path, int direction, Object tag, boolean ignoreBackLinks) + { + Vertex[] children = null; + int i = 0; + + if(direction == kDown) + { + children = graphModel.getOutVertices(vertex); + } + else + { + children = graphModel.getInVertices(vertex); + } + + vertex.setTag(tag); + path.add(vertex); + + for(i=0; i