Class RootToLeafPathsMaker<T>
java.lang.Object
io.openml.gearbox.binarytree.pathvisitor.AbstractRootToLeafPathVisitor<T,List<Path<T>>>
io.openml.gearbox.binarytree.pathvisitor.RootToLeafPathsMaker<T>
- Type Parameters:
T
- The type of value store in the node of the original tree
RootToLeafPathsMaker
constructs and maintains an immutable list of root-to-leaf paths of a binary tree.
For example, all root-to-leaf paths of
1 / \ 2 3 / \ \ 4 5 6are [1 -> 2 -> 4 -> x, 1 -> 2 -> 5 -> x, 1 -> 3 -> 6 -> x]
All paths are constructed in O(n * h) time and O(n) space complexity, where n is the number of nodes in the binary tree and h the height of the binary tree
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> RootToLeafPathsMaker<T>
constructFor
(TreeNode<T> root) Constructs all root-to-leaf paths of a specified binary tree.protected void
constructTreePaths
(TreeNode<T> root, Path<T> path) Deprecated.recursion is inefficient on large treeReturns an immutable view of all the root-to-leaf paths of the wrapped tree.Retrieves the result of the path-traversal.protected void
Performs action while path-traversal is visiting aleaf node
.Methods inherited from class io.openml.gearbox.binarytree.pathvisitor.AbstractRootToLeafPathVisitor
visit
-
Constructor Details
-
RootToLeafPathsMaker
public RootToLeafPathsMaker()
-
-
Method Details
-
constructFor
Constructs all root-to-leaf paths of a specified binary tree.- Type Parameters:
T
- The type of value store in the node of the original tree- Parameters:
root
- The root of the binary tree- Returns:
- a new
RootToLeafPathsMaker
instance. - Throws:
NullPointerException
- ifroot
isnull
-
getAllPaths
Returns an immutable view of all the root-to-leaf paths of the wrapped tree.This method returns the same result as
getVisitResult()
.- Returns:
- a list of paths, each follows the root-to-leaf order
-
getVisitResult
Description copied from class:AbstractRootToLeafPathVisitor
Retrieves the result of the path-traversal.AbstractRootToLeafPathVisitor.visit(TreeNode)
must be called before calling this method; otherwise the behavior of this method is not defined.- Specified by:
getVisitResult
in classAbstractRootToLeafPathVisitor<T,
List<Path<T>>> - Returns:
- identity to be calculated by path-traversal
-
visitLeaf
Description copied from class:AbstractRootToLeafPathVisitor
Performs action while path-traversal is visiting aleaf node
.For example, while path-traversing the following tree
1 / \ 2 3 / \ \ 4 5 6
AbstractRootToLeafPathVisitor.visitLeaf(Path)
is called at node 4, 5, and 6.- Specified by:
visitLeaf
in classAbstractRootToLeafPathVisitor<T,
List<Path<T>>> - Parameters:
path
- A complete root-to-leaf path ending on the leaf being visited; for example, when callingAbstractRootToLeafPathVisitor.visitLeaf(Path)
at node 4,path
is1 -> 2 -> 4
; at node 5,path
is1 -> 2 -> 5
; at node 6,path
is1 -> 3 -> 6
-
constructTreePaths
Deprecated.recursion is inefficient on large treeComputes all root-to-leaf paths of a binary tree recursively.- Parameters:
root
- the root of the binary treepath
- a path under construction, caller of this recursive method should initially pass an empty path argument
-