jdsl.core.api
Interface Tree
- public abstract interface Tree
- extends InspectableTree
Seperates the methods cut, link, and replaceSubtree out of BinaryTree
so that faster implementations of BinaryTree can be created.
- Author:
- Mike Boilen
|
Method Summary |
Tree |
cut(Position root)
This tree is cut above the position passed in, and that position is replaced
with an external node with a null element. |
void |
link(Position mustBeExternal,
Tree newSubtree)
Position mustBeExternal is removed from the tree, and its locator is
made uncontained. |
Tree |
replaceSubtree(Position subtreeRoot,
Tree newSubtree)
Swap out the tree rooted at subtreeRoot and replace it with the
newSubtree passed in. |
cut
public Tree cut(Position root)
throws InvalidPositionException
- This tree is cut above the position passed in, and that position is replaced
with an external node with a null element. The subtree cut off at
that point is returned to the user as a new Tree.
- Parameters:
root - The position above which to make the cut; will be the
root of the tree passed back- Returns:
- the subtree cut off of the tree.
- Throws:
- InvalidPositionException - if position is null or incompatible
with this container
link
public void link(Position mustBeExternal,
Tree newSubtree)
throws InvalidPositionException
- Position mustBeExternal is removed from the tree, and its locator is
made uncontained. The root of newSubtree, with all its children
and associated locators and elements, is attached as the new child
of mustBeExternal's parent. newSubtree becomes invalid.
- Parameters:
root - The position to insert the new Subtree.newSubtree - The subtree to insert at the position.- Throws:
- InvalidPositionException - if position is null or incompatible
with this container
replaceSubtree
public Tree replaceSubtree(Position subtreeRoot,
Tree newSubtree)
throws InvalidPositionException
- Swap out the tree rooted at subtreeRoot and replace it with the
newSubtree passed in. The subtree removed is returned as a new
Tree. The Tree passed in becomes invalid.
- Parameters:
subtreeRoot - A position in the DynamicBinaryTree on which
the method is callednewSubtree - The subtree which is to be inserted in the place
subTreeRoot currently occupies.- Returns:
- A new tree, with subtreeRoot as its root
- Throws:
- InvalidPositionException - if position is null or incompatible
with this container