private abstract static class Traverser.Traversal<N>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
(package private) SuccessorsFunction<N> |
successorFunction |
Constructor and Description |
---|
Traversal(SuccessorsFunction<N> successorFunction) |
Modifier and Type | Method and Description |
---|---|
(package private) java.util.Iterator<N> |
breadthFirst(java.util.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) |
(package private) java.util.Iterator<N> |
postOrder(java.util.Iterator<? extends N> startNodes) |
(package private) java.util.Iterator<N> |
preOrder(java.util.Iterator<? extends N> startNodes) |
private java.util.Iterator<N> |
topDown(java.util.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 |
visitNext(java.util.Deque<java.util.Iterator<? extends N>> horizon)
Visits the next node from the top iterator of
horizon and returns the visited node. |
final SuccessorsFunction<N> successorFunction
Traversal(SuccessorsFunction<N> successorFunction)
static <N> Traverser.Traversal<N> inGraph(SuccessorsFunction<N> graph)
static <N> Traverser.Traversal<N> inTree(SuccessorsFunction<N> tree)
private java.util.Iterator<N> topDown(java.util.Iterator<? extends N> startNodes, Traverser.InsertionOrder order)
InsertionOrder
parameter: nieces are placed at the FRONT before
aunts for pre-order; while in BFS they are placed at the BACK after aunts.abstract N visitNext(java.util.Deque<java.util.Iterator<? extends N>> horizon)
horizon
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 of visitNext()
often insert additional iterators
into horizon
between calls to visitNext()
. This causes them to receive
additional values interleaved with those shown above.)