public final class Traversal extends Object
An object of this class can be instantiated on an Topology, and then used to perform more efficient graph traversals. The contents of this class are valid only while the graph structure is maintained. As soon as the graph is modified, this object must be discarded and a new one created.
A traversal stores only the "forward" direction of a graph. If a client wants to be able to traverse a graph in both directions, then it will need to create a traversal on the graph, reverse the graph and create a traversal on the reversed graph, and then reverse the graph back again.
Although it seems like the approach like constructing a new Traversal object many times is inefficient, it is actually not. I also wrote a class the contained the data and functionality of both Topology and Traversal. As edges were added, the arrays of successor/predecessor nodes were updated each time. This class was consistently slower (by 10% - 25%) than constructing separate Traversal objects. Probably something to do with the way the java optimizer works. Also, the code was trickier when deleting things, so I left it like this. The performance is still about 50 times better than diva.graph.
If a graph becomes very sparse through a lot of node deletion, this class will get a little (time and space) inefficient. This can be avoided by compacting the graph first.
Constructor and Description |
---|
Traversal(Topology top)
Create a new traversal on the given topology
|
Modifier and Type | Method and Description |
---|---|
int |
getEdgeCount(int node)
Return the number of edges leaving the given node.
|
int[] |
getEdges(int node)
Return the array of edges leaving the given node.
|
int |
getNodeCount()
Return the number of nodes in the graph
|
int[] |
getNodes()
Return the array of nodes in the graph.
|
int |
getRootCount()
Return the number of roots of the graph
|
int[] |
getRoots()
Return the array of roots of the graph.
|
int |
getSuccessorCount(int node)
Return the number of successors of the given node.
|
int[] |
getSuccessors(int node)
Return the array of successors of the given node.
|
public Traversal(Topology top)
public int getEdgeCount(int node)
public int[] getEdges(int node)
public int getRootCount()
public int[] getRoots()
public int getNodeCount()
public int[] getNodes()
public int getSuccessorCount(int node)
public int[] getSuccessors(int node)
Copyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.