Package org.arakhne.afc.math.tree
Interface Tree<D,N extends TreeNode<D,?>>
-
- Type Parameters:
D
- is the type of the data inside the treeN
- is the type of the tree nodes.
- All Superinterfaces:
Iterable<N>
- All Known Subinterfaces:
BroadFirstIterableTree<D,N>
,DepthFirstIterableTree<D,N>
- All Known Implementing Classes:
AbstractTree
,LinkedTree
public interface Tree<D,N extends TreeNode<D,?>> extends Iterable<N>
This is the generic implementation of a tree.This is the public interface for a tree which is independent of the tree implementation.
- Since:
- 13.0
- Version:
- 17.0 2020-01-04 14:41:41
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- mathtree
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Iterator<N>
broadFirstIterator()
Replies a broad first iterator on nodes.void
clear()
Clear the tree.Iterator<D>
dataBroadFirstIterator()
Replies the broad-first iterator on the tree.Iterator<D>
dataDepthFirstIterator()
Replies a prefixed depth first iterator on the tree.Iterator<D>
dataDepthFirstIterator(int infixPosition)
Replies the depth first iterator on the tree.Iterator<D>
dataDepthFirstIterator(DepthFirstNodeOrder nodeOrder)
Replies a depth first iterator on the tree.Iterator<N>
depthFirstIterator()
Replies a depth-first iterator on nodes.Iterator<N>
depthFirstIterator(DepthFirstNodeOrder nodeOrder)
Replies a depth-first iterator on nodes.int[]
getHeights()
Replies the heights of all the leaf nodes.int
getMaxHeight()
Replies the maximal height of the tree.int
getMinHeight()
Replies the minimal height of the tree.int
getNodeCount()
Replies the count of nodes inside this tree.N
getRoot()
Replies the root of the tree.int
getUserDataCount()
Replies the count of data inside this tree.boolean
isEmpty()
Replies if this tree contains user data.void
setRoot(N newRoot)
Set the root of the tree.-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
-
-
Method Detail
-
getRoot
@Pure N getRoot()
Replies the root of the tree.- Returns:
- the root of the tree.
-
setRoot
void setRoot(N newRoot)
Set the root of the tree.- Parameters:
newRoot
- is the new root node.
-
clear
void clear()
Clear the tree.Caution: this method also destroyes the links between the nodes inside the tree. If you want to unlink the root node with this tree but leave the nodes' links unchanged, please call
setRoot(null)
.
-
getNodeCount
@Pure int getNodeCount()
Replies the count of nodes inside this tree.- Returns:
- the count of nodes inside the whole tree.
-
getUserDataCount
@Pure int getUserDataCount()
Replies the count of data inside this tree.- Returns:
- the count of user objects inside the whole tree.
-
isEmpty
@Pure boolean isEmpty()
Replies if this tree contains user data.- Returns:
true
if the tree is empty (no user data), otherwisefalse
-
getMinHeight
@Pure int getMinHeight()
Replies the minimal height of the tree.- Returns:
- the height of the uppest leaf in the tree.
-
getMaxHeight
@Pure int getMaxHeight()
Replies the maximal height of the tree.- Returns:
- the height of the lowest leaf in the tree.
-
getHeights
@Pure int[] getHeights()
Replies the heights of all the leaf nodes. The order of the heights is given by a depth-first iteration.- Returns:
- the heights of the leaf nodes
-
depthFirstIterator
@Pure Iterator<N> depthFirstIterator(DepthFirstNodeOrder nodeOrder)
Replies a depth-first iterator on nodes.- Parameters:
nodeOrder
- indicates how the data are treated by the iterator.- Returns:
- a depth first iterator on nodes
-
depthFirstIterator
@Pure Iterator<N> depthFirstIterator()
Replies a depth-first iterator on nodes.- Returns:
- a depth-first iterator.
-
broadFirstIterator
@Pure Iterator<N> broadFirstIterator()
Replies a broad first iterator on nodes.- Returns:
- a broad first iterator.
-
dataDepthFirstIterator
@Pure Iterator<D> dataDepthFirstIterator()
Replies a prefixed depth first iterator on the tree.- Returns:
- a prefixed depth first iterator on data.
-
dataDepthFirstIterator
@Pure Iterator<D> dataDepthFirstIterator(DepthFirstNodeOrder nodeOrder)
Replies a depth first iterator on the tree.- Parameters:
nodeOrder
- indicates how the data are treated by the iterator.- Returns:
- an iterator on the data.
-
dataDepthFirstIterator
@Pure Iterator<D> dataDepthFirstIterator(int infixPosition)
Replies the depth first iterator on the tree.- Parameters:
infixPosition
- is the index at which the parent will be treated according to its child set.- Returns:
- the iterator on user data
- See Also:
InfixDepthFirstTreeIterator
-
-