SuccessorsFunction.
There are two entry points for creating a Traverser: forTree(SuccessorsFunction) and forGraph(SuccessorsFunction). You should choose one
based on your answers to the following questions:
equals()/hashCode() recursive?
If your answers are:
forGraph(SuccessorsFunction).
forTree(SuccessorsFunction).
forTree() will be more efficient.
forGraph().
| Modifier and Type | Class and Description |
|---|---|
| private static enum | Traverser.
Poor man's method reference for |
| private abstract static class |
| Modifier and Type | Field and Description |
|---|---|
| private final SuccessorsFunction |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public final Iterable | breadthFirst(N startNode)
Returns an unmodifiable |
| public final Iterable | breadthFirst(Iterable<? extends N> startNodes)
Returns an unmodifiable |
| public final Iterable | depthFirstPostOrder(N startNode)
Returns an unmodifiable |
| public final Iterable | depthFirstPostOrder(Iterable<? extends N> startNodes)
Returns an unmodifiable |
| public final Iterable | depthFirstPreOrder(N startNode)
Returns an unmodifiable |
| public final Iterable | depthFirstPreOrder(Iterable<? extends N> startNodes)
Returns an unmodifiable |
| public static <N> Traverser | forGraph(SuccessorsFunction<N>
SuccessorsFunction representing a general graph that may have cycles.Creates a new traverser for the given general |
| public static <N> Traverser | forTree(SuccessorsFunction<N>
SuccessorsFunction representing a directed acyclic graph that has at most
one path between any two nodesCreates a new traverser for a directed acyclic graph that has at most one path from the start node(s) to any node reachable from the start node(s), and has no paths from any start node to any other start node, such as a tree or forest. |
| pack-priv abstract Traverser. | |
| private ImmutableSet |
| successorFunction | back to summary |
|---|---|
| private final SuccessorsFunction<N> successorFunction | |
| Traverser | back to summary |
|---|---|
| private Traverser(SuccessorsFunction<N> successorFunction) | |
| breadthFirst | back to summary |
|---|---|
| public final Iterable Returns an unmodifiable Example: The following graph with
The behavior of this method is undefined if the nodes, or the topology of the graph, change while iteration is in progress. The returned
See Wikipedia for more info.
| |
| breadthFirst | back to summary |
|---|---|
| public final Iterable Returns an unmodifiable
| |
| depthFirstPostOrder | back to summary |
|---|---|
| public final Iterable Returns an unmodifiable Example: The following graph with
The behavior of this method is undefined if the nodes, or the topology of the graph, change while iteration is in progress. The returned
See Wikipedia for more info.
| |
| depthFirstPostOrder | back to summary |
|---|---|
| public final Iterable Returns an unmodifiable
| |
| depthFirstPreOrder | back to summary |
|---|---|
| public final Iterable Returns an unmodifiable Example: The following graph with
The behavior of this method is undefined if the nodes, or the topology of the graph, change while iteration is in progress. The returned
See Wikipedia for more info.
| |
| depthFirstPreOrder | back to summary |
|---|---|
| public final Iterable Returns an unmodifiable
| |
| forGraph | back to summary |
|---|---|
| public static <N> Traverser Creates a new traverser for the given general Traversers created using this method are guaranteed to visit each node reachable from the start node(s) at most once. If you know that no node in Performance notes
| |
| forTree | back to summary |
|---|---|
| public static <N> Traverser Creates a new traverser for a directed acyclic graph that has at most one path from the start node(s) to any node reachable from the start node(s), and has no paths from any start node to any other start node, such as a tree or forest.
Providing a graph to be traversed for which there is more than one path from the start node(s) to any node may lead to:
Performance notes
Examples (all edges are directed facing downwards) The graph below would be valid input with start nodes of
. The graph below would be a valid input with start nodes of
Note on binary trees This method can be used to traverse over a binary tree. Given methods
| |
| newTraversal | back to summary |
|---|---|
| pack-priv abstract Traverser. | |
| validate | back to summary |
|---|---|
private ImmutableSet
| |
Deque::addFirst and Deque::addLast.
| Modifier and Type | Field and Description |
|---|---|
| public static final Traverser. | |
| public static final Traverser. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv abstract <T> void | |
| public static Traverser. | |
| public static Traverser. |
| BACK | back to summary |
|---|---|
| public static final Traverser. | |
| FRONT | back to summary |
|---|---|
| public static final Traverser. | |
| InsertionOrder | back to summary |
|---|---|
| private InsertionOrder() | |
| insertInto | back to summary |
|---|---|
| pack-priv abstract <T> void insertInto(Deque<T> deque, T value) | |
| valueOf | back to summary |
|---|---|
| public static Traverser. | |
| values | back to summary |
|---|---|
| public static Traverser. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final SuccessorsFunction |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv final Iterator | |
| pack-priv static <N> Traverser. | |
| pack-priv static <N> Traverser. | |
| pack-priv final Iterator | |
| pack-priv final Iterator | |
| private Iterator | topDown(Iterator<? extends N> startNodes, Traverser.
In top-down traversal, an ancestor node is always traversed before any of its descendant nodes. |
| pack-priv abstract N |
| successorFunction | back to summary |
|---|---|
| pack-priv final SuccessorsFunction<N> successorFunction | |
| Traversal | back to summary |
|---|---|
| pack-priv Traversal(SuccessorsFunction<N> successorFunction) | |
| breadthFirst | back to summary |
|---|---|
| pack-priv final Iterator | |
| inGraph | back to summary |
|---|---|
| pack-priv static <N> Traverser. | |
| inTree | back to summary |
|---|---|
| pack-priv static <N> Traverser. | |
| postOrder | back to summary |
|---|---|
| pack-priv final Iterator | |
| preOrder | back to summary |
|---|---|
| pack-priv final Iterator | |
| topDown | back to summary |
|---|---|
| private Iterator 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 the | |
| visitNext | back to summary |
|---|---|
| pack-priv abstract N visitNext(Deque<Iterator<? extends N>> horizon) Visits the next node from the top iterator of For example, if horizon is
| |