Class DepthCalculator<T>
java.lang.Object
io.openml.gearbox.binarytree.pathvisitor.AbstractRootToLeafPathVisitor<T,Integer>
io.openml.gearbox.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.int
getDepth()
Returns the pre-computed tree height.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
-
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: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,
Integer> - 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,
Integer> - 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
-