|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjdsl.core.ref.AbstractPositionalContainer
jdsl.core.ref.NodeTree
A node-based Tree. The Positions of the tree are the nodes.
cut(), link(), and replaceSubtree() are implemented with O(n) running times to support size() and contains() having O(1) running times. Rank related methods are O(the maximum number of children per node). The tree is implemented with a internal node data structure which keeps track of the structure of the tree (i.e. links to parents, siblings, and children).
| Constructor Summary | |
NodeTree()
The default constructor for NodeTree, which creates a tree with one node whose element is null. |
|
| Method Summary | |
Position |
childAtRank(Position node,
int rank)
O(1) time |
PositionIterator |
children(Position node)
O(1) time if cache exists, O(the number of children of the node) otherwise. |
boolean |
contains(Accessor a)
O(1) time |
Object |
contract(Position node)
O(1) time |
Tree |
cut(Position p)
O(size of the cut subtree) time |
ObjectIterator |
elements()
O(1) time if cache already exists, O(size of the tree) otherwise |
Position |
expand(Position fromChild,
Position toChild,
Object elem)
O(number of children of a new node) time |
Position |
firstChild(Position node)
O(1) time |
Position |
insertAfterSibling(Position node,
Object elem)
O(1) time |
Position |
insertBeforeSibling(Position node,
Object elem)
O(1) time |
Position |
insertChildAtRank(Position node,
int rank,
Object elem)
O(the number of children of the node) time |
Position |
insertFirstChild(Position node,
Object elem)
O(1) time |
Position |
insertLastChild(Position node,
Object elem)
O(1) time |
boolean |
isEmpty()
O(1) time |
boolean |
isExternal(Position node)
O(1) time |
boolean |
isInternal(Position node)
O(1) time |
boolean |
isRoot(Position node)
O(1) time |
Position |
lastChild(Position node)
O(1) time |
Object |
link(Position extNode,
Tree t)
O(size of the new subtree to be linked in) time |
Container |
newContainer()
O(1) time |
int |
numChildren(Position node)
O(1) time |
Position |
parent(Position node)
O(1) time |
PositionIterator |
positions()
O(1) time if cache already exists, O(size of the tree) otherwise |
int |
rankOfChild(Position child)
O(the number of children of the node) time |
Object |
removeExternal(Position node)
O(1) time |
Object |
replaceElement(Accessor a,
Object newElement)
O(1) time |
Tree |
replaceSubtree(Position node,
Tree t)
O(size of the new subtree + size of the cut tree) time |
Position |
root()
O(1) time |
Position |
siblingAfter(Position node)
O(1) time |
Position |
siblingBefore(Position node)
O(the number of children of the node) time |
PositionIterator |
siblings(Position node)
O(the number of children of the node) time |
int |
size()
O(1) time |
void |
swapElements(Position a,
Position b)
O(1) time |
String |
toString()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public NodeTree()
| Method Detail |
public boolean contains(Accessor a)
throws InvalidAccessorException
contains in interface InspectableContainerInvalidAccessorException - if a is nullpublic boolean isEmpty()
isEmpty in interface InspectableContainerisEmpty in class AbstractPositionalContainerpublic int size()
size in interface InspectableContainerpublic ObjectIterator elements()
elements in interface InspectableContainerpublic Container newContainer()
newContainer in interface Container
public Object replaceElement(Accessor a,
Object newElement)
throws InvalidAccessorException
replaceElement in interface Containera - Accessor in this containernewElement - to be stored at a
InvalidAccessorException - if a is null or does not
belong to this containerpublic PositionIterator positions()
positions in interface InspectablePositionalContainer
public void swapElements(Position a,
Position b)
throws InvalidAccessorException
swapElements in interface PositionalContainerswapElements in class AbstractPositionalContainerInvalidAccessorException
public boolean isRoot(Position node)
throws InvalidAccessorException
isRoot in interface InspectableTreenode - a node
true if node is the root of this tree
InvalidAccessorException - if node is null or
does not belong to this tree
public boolean isInternal(Position node)
throws InvalidAccessorException
isInternal in interface InspectableTreenode - a node
true if node has at least one child
InvalidAccessorException - if node is null or
does not belong to this tree
public boolean isExternal(Position node)
throws InvalidAccessorException
isExternal in interface InspectableTreenode - Any node of the tree
true if node has no children
InvalidAccessorException - if node is null or
does not belong to this treepublic Position root()
root in interface InspectableTree
public Position parent(Position node)
throws BoundaryViolationException,
InvalidAccessorException
parent in interface InspectableTreenode - a node
BoundaryViolationException - if node is the
root of the tree
InvalidAccessorException - if node is null or
does not belong to this tree
public PositionIterator children(Position node)
throws InvalidAccessorException
children in interface InspectableTreenode - a node of the tree
InvalidAccessorException - if node is null or
does not belong to this tree
public PositionIterator siblings(Position node)
throws BoundaryViolationException,
InvalidAccessorException
siblings in interface InspectableTreenode - a node of the tree
InvalidAccessorException - if node is null or
does not belong to this tree
BoundaryViolationException - if node is the
root of the tree
public int numChildren(Position node)
throws InvalidAccessorException
numChildren in interface InspectableTreenode - a node of the tree
node
InvalidAccessorException - if node is null or
does not belong to this tree
public Position siblingAfter(Position node)
throws BoundaryViolationException,
InvalidAccessorException
siblingAfter in interface InspectableTreenode - a node
node
InvalidAccessorException - if node is null
or does not belong to this tree
BoundaryViolationException - if node is
either the last child of a node or the root
public Position childAtRank(Position node,
int rank)
throws BoundaryViolationException,
InvalidAccessorException
childAtRank in interface InspectableTreenode - a noderank - an integer index of the children of
node; childAtRank(0) is the first child,
childAtRank(numChildren(node)-1) is the last child
node at the specified rank
BoundaryViolationException - if rank < 0 or rank >
numChildren(node)-1 or node is a leaf
InvalidAccessorException - if node is null
or does not belong to this tree
public Position siblingBefore(Position node)
throws BoundaryViolationException,
InvalidAccessorException
siblingBefore in interface InspectableTreenode - a node
node
BoundaryViolationException - if node is
either the first child of a node or the root
InvalidAccessorException - if node is null
or does not belong to this tree
public Position firstChild(Position node)
throws BoundaryViolationException,
InvalidAccessorException
firstChild in interface InspectableTreenode - a node
node
InvalidAccessorException - if node is null
or does not belong to this tree
BoundaryViolationException - if node is
a leaf
public Position lastChild(Position node)
throws BoundaryViolationException,
InvalidAccessorException
lastChild in interface InspectableTreenode - a node
node
BoundaryViolationException - if node is
a leaf
InvalidAccessorException - if node is null
or does not belong to this tree
public int rankOfChild(Position child)
throws BoundaryViolationException,
InvalidAccessorException
rankOfChild in interface InspectableTreechild - a node
child
BoundaryViolationException - if child is
the root
InvalidAccessorException - if child is null
or does not belong to this tree
public Tree cut(Position p)
throws InvalidAccessorException
cut in interface Treep - The position above which to make the cut;
will be the root of the returned tree
InvalidAccessorException - if node is null
or does not belong to this tree.
public Object link(Position extNode,
Tree t)
throws InvalidAccessorException,
InvalidContainerException
link in interface TreeextNode - The position to insert the tree
t at.t - The subtree to insert at the position.
extNode
InvalidContainerException - if t is null,
incompatible with, or equal to this tree.
InvalidAccessorException - if extNode is
not external, is null, or does not belong to this tree.
public Tree replaceSubtree(Position node,
Tree t)
throws InvalidAccessorException,
InvalidContainerException
replaceSubtree in interface Treenode - a nodet - the tree that will replace the tree rooted
at node
node as its root
InvalidAccessorException - if node is null
or does not belong to this tree.
InvalidContainerException - if t is null,
incompatible with, or equal to this tree.
public Position insertAfterSibling(Position node,
Object elem)
throws BoundaryViolationException,
InvalidAccessorException
insertAfterSibling in interface Treenode - a node different from the rootelem - the object to be stored in the new node
BoundaryViolationException - if node is the root
InvalidAccessorException - if node is null
or does not belong to this tree
public Position insertChildAtRank(Position node,
int rank,
Object elem)
throws BoundaryViolationException,
InvalidAccessorException
insertChildAtRank in interface Treenode - a noderank - an integer index of the children of node
from 0 to numChildren(node) (inclusive)elem - the object to be stored in the new node
InvalidAccessorException - if node is null
or does not belong to this tree
BoundaryViolationException - if rank < 0 or
rank > numChildren(node)
public Position insertBeforeSibling(Position node,
Object elem)
throws BoundaryViolationException,
InvalidAccessorException
insertBeforeSibling in interface Treenode - a nodeelem - the object to be stored in the new node
InvalidAccessorException - if node is null
or does not belong to this tree
BoundaryViolationException - if node is the root
public Position insertFirstChild(Position node,
Object elem)
throws InvalidAccessorException
insertFirstChild in interface Treenode - a nodeelem - the object to be stored in the new node
InvalidAccessorException - if node is null
or does not belong to this tree
public Position insertLastChild(Position node,
Object elem)
throws InvalidAccessorException
insertLastChild in interface Treenode - a nodeelem - the object to be stored in the new node
InvalidAccessorException - if node is null
or does not belong to this tree
public Object removeExternal(Position node)
throws BoundaryViolationException,
InvalidAccessorException
removeExternal in interface Treenode - a leaf node different from the root
node
BoundaryViolationException - if node is not
external or is the root
InvalidAccessorException - if node is null
or does not belong to this tree
public Object contract(Position node)
throws BoundaryViolationException,
InvalidAccessorException
contract in interface Treenode - a node
node
BoundaryViolationException - if node is the
root or an external node
InvalidAccessorException - if node is null
or does not belong to this tree
public Position expand(Position fromChild,
Position toChild,
Object elem)
throws InvalidAccessorException
expand in interface TreefromChild - a nodetoChild - any higher-ranked sibling of
fromChild or fromChild itselfelem - the object to be stored in the new node
InvalidAccessorException - if fromChild and
toChild are not siblings, or if toChild
is a lower-ranked sibling of fromChild, or if either
of them is null or does not belong to this treepublic String toString()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||