public abstract class TreeTraversal
extends java.lang.Object
T
as nodes in a tree, and provides methods to traverse the trees
induced by this traverser.
For example, the tree
h
/ | \
* / e \
* d g
/|\ |
/ | \ f
a b c
can be iterated over in pre-order (hdabcegf), post-order (abcdefgh), or breadth-first order (hdegabcf).
Null nodes are strictly forbidden.
Modifier and Type | Class and Description |
---|---|
static class |
TreeTraversal.GuidedIt<T> |
static class |
TreeTraversal.It<T> |
static class |
TreeTraversal.TracingIt<T> |
static class |
TreeTraversal.TraversalArgs<T> |
static interface |
TreeTraversal.TraversalInterceptor |
Modifier and Type | Field and Description |
---|---|
static TreeTraversal |
BI_ORDER_DFS
Returns an iterator over the nodes in a tree structure, using bi-order traversal.
|
static TreeTraversal |
INTERLEAVED_DFS
Returns an iterator over the nodes in a tree structure, using interlaced pre-order DFS traversal.
|
static TreeTraversal |
LEAVES_BFS
Returns an iterator over the leaf nodes only in a tree structure, using BFS traversal.
|
static TreeTraversal |
LEAVES_DFS
Returns an iterator over the leaf nodes only in a tree structure, using DFS traversal.
|
static TreeTraversal |
PLAIN_BFS
Returns an iterator over the nodes in a tree structure, using breadth-first traversal.
|
static TreeTraversal |
POST_ORDER_DFS
Returns an iterator over the nodes in a tree structure, using post-order DFS traversal.
|
static TreeTraversal |
PRE_ORDER_DFS
Returns an iterator over the nodes in a tree structure, using pre-order traversal.
|
static TreeTraversal |
TRACING_BFS
Same as
PLAIN_BFS but with TracingIt . |
Modifier | Constructor and Description |
---|---|
protected |
TreeTraversal(java.lang.String debugName) |
Modifier and Type | Method and Description |
---|---|
TreeTraversal |
cached(java.util.Map<java.lang.Object,java.lang.Object> cache)
Configures the traversal to cache its structure.
|
abstract <T> TreeTraversal.It<T> |
createIterator(java.lang.Iterable<? extends T> roots,
Function<? super T,? extends java.lang.Iterable<? extends T>> tree)
Creates a new iterator for this type of traversal.
|
static TreeTraversal |
GUIDED_TRAVERSAL(TreeTraversal.GuidedIt.Guide<?> guide) |
TreeTraversal |
intercept(java.lang.String debugName,
TreeTraversal.TraversalInterceptor interceptor) |
<T> TreeTraversal |
onRange(Condition<T> rangeCondition)
Configures the traversal to expand and return the nodes within the range only.
|
java.lang.String |
toString() |
<T> Function<T,JBIterable<T>> |
traversal(Function<? super T,? extends java.lang.Iterable<? extends T>> tree) |
<T> JBIterable<T> |
traversal(java.lang.Iterable<? extends T> roots,
Function<? super T,? extends java.lang.Iterable<? extends T>> tree) |
<T> JBIterable<T> |
traversal(T root,
Function<? super T,? extends java.lang.Iterable<? extends T>> tree) |
TreeTraversal |
unique()
Configures the traversal to skip already visited nodes.
|
TreeTraversal |
unique(Function<?,?> identity)
Configures the traversal to skip already visited nodes.
|
public static final TreeTraversal BI_ORDER_DFS
No guarantees are made about the behavior of the traversal when nodes change while
iteration is in progress or when the iterators generated by tree
are advanced.
public static final TreeTraversal PRE_ORDER_DFS
No guarantees are made about the behavior of the traversal when nodes change while
iteration is in progress or when the iterators generated by tree
are advanced.
public static final TreeTraversal POST_ORDER_DFS
No guarantees are made about the behavior of the traversal when nodes change while
iteration is in progress or when the iterators generated by tree
are advanced.
public static final TreeTraversal LEAVES_DFS
public static final TreeTraversal INTERLEAVED_DFS
No guarantees are made about the behavior of the traversal when nodes change while
iteration is in progress or when the iterators generated by tree
are advanced.
public static final TreeTraversal PLAIN_BFS
No guarantees are made about the behavior of the traversal when nodes change while
iteration is in progress or when the iterators generated by tree
are advanced.
public static final TreeTraversal TRACING_BFS
PLAIN_BFS
but with TracingIt
.
That is, a path to the current node can be retrieved during some traversal.TreeTraversal.TracingIt
public static final TreeTraversal LEAVES_BFS
public abstract <T> TreeTraversal.It<T> createIterator(java.lang.Iterable<? extends T> roots, Function<? super T,? extends java.lang.Iterable<? extends T>> tree)
roots
- tree rootstree
- tree structure the children for parent function.
May return null (useful for map representation).public final <T> JBIterable<T> traversal(java.lang.Iterable<? extends T> roots, Function<? super T,? extends java.lang.Iterable<? extends T>> tree)
public final <T> JBIterable<T> traversal(T root, Function<? super T,? extends java.lang.Iterable<? extends T>> tree)
public final <T> Function<T,JBIterable<T>> traversal(Function<? super T,? extends java.lang.Iterable<? extends T>> tree)
public final TreeTraversal unique()
unique(Function)
public final TreeTraversal unique(Function<?,?> identity)
identity
- functionpublic final TreeTraversal cached(java.util.Map<java.lang.Object,java.lang.Object> cache)
public final <T> TreeTraversal onRange(Condition<T> rangeCondition)
rangeCondition
return true for the first time,
processes as usual the nodes while the condition return true and
stops when the rangeCondition
return false after that.public final TreeTraversal intercept(java.lang.String debugName, TreeTraversal.TraversalInterceptor interceptor)
public final java.lang.String toString()
toString
in class java.lang.Object
public static TreeTraversal GUIDED_TRAVERSAL(TreeTraversal.GuidedIt.Guide<?> guide)