Class RootToLeafPathsMaker<T>
java.lang.Object
io.openml.gearbox.algorithms.binarytree.pathvisitor.AbstractRootToLeafPathVisitor<T, List<Path<T>>>
io.openml.gearbox.algorithms.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 6
are [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 voidconstructTreePaths(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 voidPerforms action while path-traversal is visiting aleaf node.Methods inherited from class 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
RootToLeafPathsMakerinstance. - Throws:
NullPointerException- ifrootisnull
-
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:AbstractRootToLeafPathVisitorRetrieves 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:
getVisitResultin classAbstractRootToLeafPathVisitor<T, List<Path<T>>>- Returns:
- identity to be calculated by path-traversal
-
visitLeaf
Description copied from class:AbstractRootToLeafPathVisitorPerforms action while path-traversal is visiting aleaf node.For example, while path-traversing the following tree
1 / \ 2 3 / \ \ 4 5 6AbstractRootToLeafPathVisitor.visitLeaf(Path)is called at node 4, 5, and 6.- Specified by:
visitLeafin 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,pathis1 -> 2 -> 4; at node 5,pathis1 -> 2 -> 5; at node 6,pathis1 -> 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
-