| 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
  |
  +--jdsl.core.ref.AbstractPositionalContainer
        |
        +--jdsl.core.ref.NodeBinaryTree
A node-based Binary Tree. The Positions of the tree are the nodes.
contains() is O(1) time; so replaceSubtree, cut, and link are O(S), where S is the number of positions in that subtree. Positions() and elements() are O(N) -- where N is the number of positions in the entire tree. All other methods are O(1) time.
Elements can be stored at both internal and external (leaf) nodes.
The data structure stores a supernode which in turn stores the root. (this supernode is invisible to the end user) You are only allowed to link in and replaceSubtree with other instances of NodeBinaryTree (or subclasses thereof).
AbstractPositionalContainer, 
BinaryTree| Inner Class Summary | |
protected static class | 
NodeBinaryTree.NBTNode
This is the class for all user-visible nodes It contains links for its parent, children, and element.  | 
protected static class | 
NodeBinaryTree.NBTSuperNode
This is the supernode.  | 
| Field Summary | |
protected  int | 
_size
The size of the tree protected so that RestructurableNodeBinaryTree can access it  | 
| Constructor Summary | |
  | 
NodeBinaryTree()
Create a tree.  | 
protected  | 
NodeBinaryTree(NodeBinaryTree.NBTNode root)
Create a tree from a set of nodes.  | 
| Method Summary | |
protected  NodeBinaryTree.NBTNode | 
checkPosition(Accessor a)
Casts the accessor passed in to the appropriate node class for this container; also checks if it is null.  | 
 Position | 
childAtRank(Position node,
            int rank)
O(1) time  | 
 PositionIterator | 
children(Position p)
O(1) time  | 
 boolean | 
contains(Accessor a)
O(1) time  | 
 BinaryTree | 
cut(Position rootOfSubtree)
Takes O(S) time, where S is the number of positions in the subtree to cut  | 
 ObjectIterator | 
elements()
Takes O(N) time from the need to iterate through the tree during snapshot, where N is the number of elements in the tree  | 
 void | 
expandExternal(Position mustBeExternal)
O(1) time  | 
 Position | 
firstChild(Position node)
O(1) time  | 
 void | 
graftOnLeft(Position subtree,
            java.lang.Object eltOfParent,
            BinaryTree newSibling)
Takes O(S) time, where S is the number of positions in the new subtree to graft on You are only allowed to link in and replaceSubtree with other instances of NodeBinaryTree (or subclasses thereof)  | 
 void | 
graftOnRight(Position subtree,
             java.lang.Object eltOfParent,
             BinaryTree newSibling)
Takes O(S) time, where S is the number of positions in the new subtree to graft on You are only allowed to link in and replaceSubtree with other instances of NodeBinaryTree (or subclasses thereof)  | 
 boolean | 
isEmpty()
Overridden from AbstractPositionalContainer to be O(1) time.  | 
 boolean | 
isExternal(Position p)
O(1) time  | 
 boolean | 
isInternal(Position p)
O(1) time  | 
 boolean | 
isRoot(Position p)
O(1) time  | 
 Position | 
lastChild(Position node)
O(1) time  | 
 Position | 
leftChild(Position p)
O(1) time  | 
 java.lang.Object | 
link(Position mustBeExternal,
     BinaryTree newSubtree)
Takes O(S) time, where S is the number of positions in this subtree You are only allowed to link in and replaceSubtree with other instances of NodeBinaryTree (or subclasses thereof)  | 
 Container | 
newContainer()
O(1) time  | 
 int | 
numChildren(Position node)
O(1) time Can be determined by the inherent nature of the type of node rather than by counting  | 
 Position | 
parent(Position p)
O(1) time  | 
 PositionIterator | 
positions()
Takes O(N) time from the need to iterate through the tree during snapshot, where N is the number of positions in the tree  | 
 int | 
rankOfChild(Position child)
O(1) time  | 
 void | 
removeAboveExternal(Position mustBeExternal)
O(1) time  | 
 java.lang.Object | 
replaceElement(Accessor p,
               java.lang.Object newElement)
O(1) time  | 
 BinaryTree | 
replaceSubtree(Position subtreeRoot,
               BinaryTree newSubtree)
Takes O(S1+S2) time, where S1 and S2 are the number of positions in each subtree You are only allowed to link in and replaceSubtree with other instances of NodeBinaryTree (or subclasses thereof)  | 
protected  void | 
resetToEmpty()
Used for resetting the tree to an empty tree after a link or replaceSubtree operation.  | 
 Position | 
rightChild(Position p)
O(1) time  | 
 Position | 
root()
O(1) time  | 
 Position | 
sibling(Position p)
O(1) time  | 
 Position | 
siblingAfter(Position node)
O(1) time  | 
 Position | 
siblingBefore(Position node)
O(1) time  | 
 PositionIterator | 
siblings(Position p)
O(1) time  | 
 int | 
size()
O(1) time  | 
 java.lang.String | 
toString()
 | 
protected  void | 
updateContainer(Accessor root)
Recursively changes the container of all nodes in the subtree anchored at root to this container, adding to _size for each node whose container we change Takes O(S) time -- where S is the number of elements in the subtree  | 
| Methods inherited from class jdsl.core.ref.AbstractPositionalContainer | 
swapElements | 
| Methods inherited from class java.lang.Object | 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait | 
| Methods inherited from interface jdsl.core.api.PositionalContainer | 
swapElements | 
| Field Detail | 
protected int _size
| Constructor Detail | 
public NodeBinaryTree()
null.
protected NodeBinaryTree(NodeBinaryTree.NBTNode root)
                  throws InvalidAccessorException
root - Root of a tree of existing nodes.InvalidAccessorException - when the given root has a parent.| Method Detail | 
public void graftOnLeft(Position subtree,
                        java.lang.Object eltOfParent,
                        BinaryTree newSibling)
graftOnLeft in interface BinaryTreejdsl.core.api.BinaryTreenewSubtree - the binary tree whose root will be linked in as
 the left child of the new nodeeltOfParent - the object to be stored in the new nodesubtreeRoot - any position in this binary treeInvalidAccessorException - if subtreeRoot
 is null or does not belong to this binary tree.InvalidContainerException - if newSubtree
 is null, incompatible with, or equal to this binary tree.
public void graftOnRight(Position subtree,
                         java.lang.Object eltOfParent,
                         BinaryTree newSibling)
graftOnRight in interface BinaryTreejdsl.core.api.BinaryTreesubtreeRoot - any position in this binary treeeltOfParent - the object to be stored in the new nodenewSubtree - the binary tree whose root will be linked in as
 the right child of the new nodeInvalidAccessorException - if subtreeRoot
 is null or does not belong to this binary tree.InvalidContainerException - if newSubtree
 is null, incompatible with, or equal to this binary tree.
public void expandExternal(Position mustBeExternal)
                    throws InvalidAccessorException
expandExternal in interface BinaryTreejdsl.core.api.BinaryTreenode - any external position in this binary treeInvalidAccessorException - if node is not
 external, is null, or does not belong to this binary tree.
public void removeAboveExternal(Position mustBeExternal)
                         throws InvalidAccessorException,
                                BoundaryViolationException
removeAboveExternal in interface BinaryTreejdsl.core.api.BinaryTreenode - any external position in this binary treeBoundaryViolationException - if node is
 an external position, as required, but also the root of this binary
 tree.InvalidAccessorException - if node is not
 external, is null, or does not belong to this binary tree.
public BinaryTree cut(Position rootOfSubtree)
               throws InvalidAccessorException
cut in interface BinaryTreejdsl.core.api.BinaryTreenode - the position above which to make the cutnode as its rootInvalidAccessorException - if node is null
 or does not belong to this binary tree.
public java.lang.Object link(Position mustBeExternal,
                             BinaryTree newSubtree)
                      throws InvalidAccessorException,
                             InvalidContainerException
link in interface BinaryTreejdsl.core.api.BinaryTreenode - the external node to replace with the new subtreenewSubtree - the subtree to link inInvalidAccessorException - if node is not
 external, is null, or does not belong to this binary tree.InvalidContainerException - if newSubtree
 is null, incompatible with, or equal to this binary tree.
public BinaryTree replaceSubtree(Position subtreeRoot,
                                 BinaryTree newSubtree)
                          throws InvalidAccessorException,
                                 InvalidContainerException
replaceSubtree in interface BinaryTreejdsl.core.api.BinaryTreesubtreeRoot - any position in this binary treenewSubtree - the binary tree that will replace the binary
 tree rooted at subtreeRootsubtreeRoot as its
 rootInvalidAccessorException - if subtreeRoot
 is null or does not belong to this binary tree.InvalidContainerException - if newSubtree
 is null, incompatible with, or equal to this binary tree.
protected void updateContainer(Accessor root)
                        throws InvalidAccessorException
root - The node to begin with
public Position leftChild(Position p)
                   throws InvalidAccessorException,
                          BoundaryViolationException
leftChild in interface InspectableBinaryTreejdsl.core.api.InspectableBinaryTreenode - Any internal node of the treenodeBoundaryViolationException - if node is
 externalInvalidAccessorException - if node is null
 or does not belong to this binary tree.
public Position rightChild(Position p)
                    throws InvalidAccessorException,
                           BoundaryViolationException
rightChild in interface InspectableBinaryTreejdsl.core.api.InspectableBinaryTreenode - Any internal node of the treenodeBoundaryViolationException - if node is
 externalInvalidAccessorException - if node is null
 or does not belong to this binary tree.
public Position sibling(Position p)
                 throws InvalidAccessorException,
                        BoundaryViolationException
sibling in interface InspectableBinaryTreejdsl.core.api.InspectableBinaryTreenode - a node of the binary tree.node.BoundaryViolationException - if node is the
 rootInvalidAccessorException - if node is null
 or does not belong to this binary tree.
public boolean isRoot(Position p)
               throws InvalidAccessorException
isRoot in interface InspectableTreejdsl.core.api.InspectableTreenode - a nodetrue if node is the root of this treeInvalidAccessorException - if node is null or
 does not belong to this tree
public boolean isInternal(Position p)
                   throws InvalidAccessorException
isInternal in interface InspectableTreejdsl.core.api.InspectableTreenode - a nodetrue if node has at least one childInvalidAccessorException - if node is null or
 does not belong to this tree
public boolean isExternal(Position p)
                   throws InvalidAccessorException
isExternal in interface InspectableTreejdsl.core.api.InspectableTreenode - Any node of the treetrue if node has no childrenInvalidAccessorException - if node is null or
 does not belong to this treepublic Position root()
root in interface InspectableTreejdsl.core.api.InspectableTree
public Position parent(Position p)
                throws InvalidAccessorException,
                       BoundaryViolationException
parent in interface InspectableTreejdsl.core.api.InspectableTreenode - a nodeBoundaryViolationException - if node is the
 root of the treeInvalidAccessorException - if node is null or
 does not belong to this tree
public PositionIterator children(Position p)
                          throws InvalidAccessorException
children in interface InspectableTreejdsl.core.api.InspectableTreenode - a node of the treeInvalidAccessorException - if node is null or
 does not belong to this tree
public PositionIterator siblings(Position p)
                          throws InvalidAccessorException
siblings in interface InspectableTreejdsl.core.api.InspectableTreenode - a node of the treeBoundaryViolationException - if node is the
 root of the treeInvalidAccessorException - if node is null or
 does not belong to this tree
public int numChildren(Position node)
                throws InvalidAccessorException
numChildren in interface InspectableTreejdsl.core.api.InspectableTreenode - a node of the treenodeInvalidAccessorException - if node is null or 
 does not belong to this tree
public Position siblingAfter(Position node)
                      throws BoundaryViolationException,
                             InvalidAccessorException
siblingAfter in interface InspectableTreejdsl.core.api.InspectableTreenode - a nodenodeBoundaryViolationException - if node is
 either the last child of a node or the rootInvalidAccessorException - if node is null
 or does not belong to this tree
public Position siblingBefore(Position node)
                       throws BoundaryViolationException,
                              InvalidAccessorException
siblingBefore in interface InspectableTreejdsl.core.api.InspectableTreenode - a nodenodeBoundaryViolationException - if node is
 either the first child of a node or the rootInvalidAccessorException - if node is null
 or does not belong to this tree
public Position firstChild(Position node)
                    throws BoundaryViolationException,
                           InvalidAccessorException
firstChild in interface InspectableTreejdsl.core.api.InspectableTreenode - a nodenodeBoundaryViolationException - if node is
 a leafInvalidAccessorException - if node is null
 or does not belong to this tree
public Position lastChild(Position node)
                   throws BoundaryViolationException,
                          InvalidAccessorException
lastChild in interface InspectableTreejdsl.core.api.InspectableTreenode - a nodenodeBoundaryViolationException - if node is
 a leafInvalidAccessorException - if node is null
 or does not belong to this tree
public int rankOfChild(Position child)
                throws BoundaryViolationException,
                       InvalidAccessorException
rankOfChild in interface InspectableTreejdsl.core.api.InspectableTreechild - a nodechildBoundaryViolationException - if child is
 the rootInvalidAccessorException - if child is null
 or does not belong to this tree
public Position childAtRank(Position node,
                            int rank)
                     throws BoundaryViolationException,
                            InvalidAccessorException
childAtRank in interface InspectableTreejdsl.core.api.InspectableTreenode - a noderank - an integer index of the children of
 node; childAtRank(0) is the first child,
 childAtRank(numChildren(node)-1) is the last childnode at the specified rankBoundaryViolationException - if rank < 0 or rank >
 numChildren(node)-1 or node is a leafInvalidAccessorException - if node is null
 or does not belong to this treepublic PositionIterator positions()
positions in interface InspectablePositionalContainerpublic ObjectIterator elements()
elements in interface InspectableContainer
public java.lang.Object replaceElement(Accessor p,
                                       java.lang.Object newElement)
                                throws InvalidAccessorException
replaceElement in interface Containerjdsl.core.api.Containera - Accessor in this containernewElement - to be stored at aInvalidAccessorException - if a is null or does not
 belong to this containerpublic Container newContainer()
newContainer in interface Containerjdsl.core.api.Containerpublic int size()
size in interface InspectableContainerpublic boolean isEmpty()
isEmpty in interface InspectableContainerisEmpty in class AbstractPositionalContainerjdsl.core.api.InspectableContainertrue if and only if the container is empty (holds
 no elements)InspectableBinaryTreepublic boolean contains(Accessor a)
contains in interface InspectableContainerjdsl.core.api.InspectableContainerInvalidAccessorException - if a is nullpublic java.lang.String toString()
toString in class java.lang.Objectprotected void resetToEmpty()
protected NodeBinaryTree.NBTNode checkPosition(Accessor a)
                                        throws InvalidAccessorException
a - The accessor to cast
  | 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||