T
- the type of node in the graphpublic class AcyclicDepthFirstPostOrderTraversalWithPayloadAndDependencyStack<T,P> extends Object
This version of algorithm tracks traversal path in DependencyStack
structure and
provides it to user in GraphTraversableWithPayloadAndDependencyStack
callback and in
result of traverse(Iterable)
operation.
If a cycle is encountered, a CycleException
is thrown by traverse(Iterable)
.
Constructor and Description |
---|
AcyclicDepthFirstPostOrderTraversalWithPayloadAndDependencyStack(GraphTraversableWithPayloadAndDependencyStack<T,P> traversable,
java.util.function.BiFunction<DependencyStack,T,DependencyStack> dependencyStackChild) |
Modifier and Type | Method and Description |
---|---|
LinkedHashMap<T,Pair<P,DependencyStack>> |
traverse(Iterable<? extends T> initialNodes)
Performs a depth-first, post-order traversal over a DAG.
|
LinkedHashMap<T,Pair<P,DependencyStack>> |
traverse(Iterable<? extends T> initialNodes,
java.util.function.Predicate<T> shouldExploreChildren)
Performs a depth-first, post-order traversal over a DAG.
|
public AcyclicDepthFirstPostOrderTraversalWithPayloadAndDependencyStack(GraphTraversableWithPayloadAndDependencyStack<T,P> traversable, java.util.function.BiFunction<DependencyStack,T,DependencyStack> dependencyStackChild)
dependencyStackChild
- a function to construct a child stack from a stack and a new graph
node. In the most cases it is just an invocation of DependencyStack.child(DependencyStack.Element)
.public LinkedHashMap<T,Pair<P,DependencyStack>> traverse(Iterable<? extends T> initialNodes) throws CycleException
initialNodes
- The nodes from which to perform the traversal. Not allowed to contain
null
.CycleException
- if a cycle is found while performing the traversal.public LinkedHashMap<T,Pair<P,DependencyStack>> traverse(Iterable<? extends T> initialNodes, java.util.function.Predicate<T> shouldExploreChildren) throws CycleException
initialNodes
- The nodes from which to perform the traversal. Not allowed to contain
null
.shouldExploreChildren
- Whether or not to explore a particular node's children. Used to
support short circuiting in the traversal.CycleException
- if a cycle is found while performing the traversal.