Package com.google.common.graph
Class Traverser.Traversal<N>
java.lang.Object
com.google.common.graph.Traverser.Traversal<N>
Abstracts away the difference between traversing a graph vs. a tree. For a tree, we just take
the next element from the next non-empty iterator; for graph, we need to loop through the next
non-empty iterator to find first unvisited node.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbreadthFirst
(Iterator<? extends N> startNodes) (package private) static <N> Traverser.Traversal
<N> inGraph
(SuccessorsFunction<N> graph) (package private) static <N> Traverser.Traversal
<N> inTree
(SuccessorsFunction<N> tree) topDown
(Iterator<? extends N> startNodes, Traverser.InsertionOrder order) In top-down traversal, an ancestor node is always traversed before any of its descendant nodes.(package private) abstract N
Visits the next node from the top iterator ofhorizon
and returns the visited node.
-
Field Details
-
successorFunction
-
-
Constructor Details
-
Traversal
Traversal(SuccessorsFunction<N> successorFunction)
-
-
Method Details
-
inGraph
-
inTree
-
breadthFirst
-
preOrder
-
topDown
In top-down traversal, an ancestor node is always traversed before any of its descendant nodes. The traversal order among descendant nodes (particularly aunts and nieces) are determined by theInsertionOrder
parameter: nieces are placed at the FRONT before aunts for pre-order; while in BFS they are placed at the BACK after aunts. -
postOrder
-
visitNext
Visits the next node from the top iterator ofhorizon
and returns the visited node. Null is returned to indicate reaching the end of the top iterator.For example, if horizon is
[[a, b], [c, d], [e]]
,visitNext()
will return[a, b, null, c, d, null, e, null]
sequentially, encoding the topological structure. (Note, however, that the callers ofvisitNext()
often insert additional iterators intohorizon
between calls tovisitNext()
. This causes them to receive additional values interleaved with those shown above.)
-