Class DepthCalculator<T>
java.lang.Object
io.openml.gearbox.algorithms.binarytree.pathvisitor.AbstractRootToLeafPathVisitor<T,Integer>
io.openml.gearbox.algorithms.binarytree.pathvisitor.DepthCalculator<T>
- Type Parameters:
T- The type of value store in the node of the original tree
Measures the depth of a binary tree.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> DepthCalculator<T> Takes the root of a binary tree and calculates the depth of the tree rooted at that node.intgetDepth()Returns the pre-computed tree height.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
-
DepthCalculator
public DepthCalculator()
-
-
Method Details
-
depthOf
Takes the root of a binary tree and calculates the depth of the tree rooted at that node.- Type Parameters:
T- The type of value store in the node of the original tree- Parameters:
root- The root of the tree whose height is to be measured- Returns:
- a new instance that stores the computed height
-
getDepth
public int getDepth()Returns the pre-computed tree height.- Returns:
- an integer
-
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,Integer> - 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,Integer> - 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
-