|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
java.lang.Object | +--com.sas.collection.AVLNode
A node for AVL tree. This class represents the nodes within an AVL tree, named after Adelson-Velskii and Landis. The nodes are threaded which means nodes which do not have a left or right child have links to the previous or next subtree; this allows for easy forward or backward enumeration of the items in the tree. Each node has either a left child or a reference to the subtree containing the previous node. Each node also has either a right child or a reference to the a subtree containing the next node.
AVLTree, Serialized Form| Inner Class Summary |
| Field Summary | |
static String |
RB_KEY
|
| Constructor Summary | |
AVLNode()
Construct a new AVLNode. |
|
AVLNode(Object object)
Construct a new AVLNode which contains an object |
|
| Method Summary | |
static AVLNode |
add(AVLNode node,
AVLNode root,
Comparator comparator,
boolean allowDuplicates)
Add a AVL node into a tree rooted at root, using the comparator. |
static AVLNode |
add(Object object,
AVLNode root,
Comparator comparator,
boolean allowDuplicates)
Add the object into a tree rooted at root, using the comparator. |
protected int |
balance()
Return a node's balance |
Object |
clone()
Clone this AVL tree node. |
static AVLNode |
find(AVLNode root,
Object object,
Comparator comparator)
Search for and return a value in the AVL tree |
Enumeration |
getItems()
Return an enumeration of the items in the tree rooted at this node. |
AVLNode.Cursor |
getItems(boolean reversedOrder)
Get an enumeration of the tree contents. |
Enumeration |
getItems(int start,
int end)
Get an enumeration of the tree contents, or a subrange of items. |
AVLNode |
getLeftChild()
Get the left child. |
AVLNode |
getLeftThread()
Get the left thread |
AVLNode |
getNextNode()
Get the next node. |
Object |
getObject()
Return the object stored at this node. |
AVLNode |
getPreviousNode()
Get the previous node. |
AVLNode |
getRightChild()
Get the right child. |
AVLNode |
getRightThread()
Get the right thread |
boolean |
hasLeftChild()
Return true if the node has a left child |
protected boolean |
hasLeftThread()
Return true if the node is left threaded, that is the leftLink() is a link to a previous node in the enumeration. |
boolean |
hasRightChild()
Return true if the node has a right child. |
protected boolean |
hasRightThread()
Return true if the node is right threaded, that is the rightLink() is a link to a next node in the enumeration. |
protected boolean |
isEvenlyBalanced()
Return true if the node has even balance. |
protected boolean |
isNegativelyBalanced()
Return true if the node has negative balance. |
protected boolean |
isPositivelyBalanced()
Return true if the node has positive balance. |
AVLNode |
leftLink()
Get the left link. |
AVLNode |
leftMostDescendent()
Return the left-most descendent |
AVLNode |
rightLink()
Get the right link. |
AVLNode |
rightMostDescendent()
Return the right-most descendent |
static AVLNode |
search(Object object,
AVLNode node,
Comparator comparator)
Search for an object in the tree rooted by node, using the comparator. |
protected void |
setBalance(int balance)
Set a node's balance to negative, even, or positive In many published algorithms, this is denoted by node.balance = a
Positive balance means the depth of the right subtree is greater than
the depth of the left subtree.
|
protected void |
setEvenBalance()
Mark the node as having even balance. |
protected void |
setLeftChild(AVLNode child)
Assign the left child node. |
protected void |
setLeftChild(AVLNode child,
AVLNode thread)
Assign the left child node or the left thread if child is null |
protected void |
setLeftThread(AVLNode prev)
Assign the previous node. |
protected void |
setNegativeBalance()
Mark the node as having negative balance. |
void |
setObject(Object object)
Set the object stored at this node. |
protected void |
setPositiveBalance()
Mark the node as having positive balance. |
protected void |
setRightChild(AVLNode child)
Assign the right child node. |
protected void |
setRightChild(AVLNode child,
AVLNode thread)
Assign the right child node, or the right thread if child is null. |
protected void |
setRightThread(AVLNode next)
Assign the next node. |
String |
toString()
Return the string representation of this node. |
String |
toString(boolean printValue,
boolean showThreads)
Return the string representation of this node. |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final String RB_KEY
| Constructor Detail |
public AVLNode()
public AVLNode(Object object)
| Method Detail |
public void setObject(Object object)
object - the object stored at this node.public Object getObject()
protected void setBalance(int balance)
node.balance = a
Positive balance means the depth of the right subtree is greater than
the depth of the left subtree.
Negative balance means the depth of the left subtree is greater than
the depth of the rightsubtree.balance - -1 for negative balance, 0 for even balance, 1 for positive balanceprotected int balance()
protected void setNegativeBalance()
node.balance == -1
Calling setNegativeBalance is equivalent to setting node.balance = -1setBalance(int)protected void setPositiveBalance()
node.balance == +1
but for space reasons, the balance is embedded within the state
variable. Calling setPositiveBalance is equivalent to setting node.balance = +1setBalance(int)protected void setEvenBalance()
node.balance == 0
but for space reasons, the balance is embedded within the state
variable. Calling setEvenBalance is equivalent to setting node.balance = 0setBalance(int)protected boolean isNegativelyBalanced()
protected boolean isPositivelyBalanced()
protected boolean isEvenlyBalanced()
public AVLNode leftLink()
protected void setLeftChild(AVLNode child,
AVLNode thread)
child - the node to assign as the left child node.thread - the node to assign as the left thread, iff child == nullprotected void setLeftChild(AVLNode child)
prev - the node to assign as the left child node.public AVLNode getLeftChild()
public AVLNode getLeftThread()
protected void setLeftThread(AVLNode prev)
prev - the node to assign as the previous node.protected boolean hasLeftThread()
public final boolean hasLeftChild()
public AVLNode rightLink()
public AVLNode getRightChild()
public AVLNode getRightThread()
protected void setRightThread(AVLNode next)
next - the node to assign as the next node.
protected void setRightChild(AVLNode child,
AVLNode thread)
child - the new right child nodethread - the node to assign as the right thread, iff child == nullprotected void setRightChild(AVLNode child)
child - the new right child nodeprotected boolean hasRightThread()
public final boolean hasRightChild()
public AVLNode getNextNode()
public AVLNode leftMostDescendent()
public AVLNode getPreviousNode()
public AVLNode rightMostDescendent()
public static AVLNode search(Object object,
AVLNode node,
Comparator comparator)
the - object to search fornode - the root node to start the searchcomparator - the comparator to use. The object
is passed as the first argument to the Comparator.compare(Object, Object)
method; the element from the AVL tree nodes is passed as the second.
public static AVLNode add(Object object,
AVLNode root,
Comparator comparator,
boolean allowDuplicates)
object - the object to insert into the treeroot - the root node. This may be nullcomparator - the Comparator to use when comparing items.allowDuplicates - if true, you can insert equal items into the tree;
a unique identifier is assigned each node and that is used to
distinguish items.
public static AVLNode add(AVLNode node,
AVLNode root,
Comparator comparator,
boolean allowDuplicates)
node - an AVL tree noderoot - the root node. This may be nullcomparator - the Comparator to use when comparing items.allowDuplicates - if true, you can insert equal items into the tree;
a unique identifier is assigned each node and that is used to
distinguish items.public Enumeration getItems()
getItems in interface Enumerablecom.sas.util.EnumerableEnumerable does not support
enumerations, the getItems() method returns null
(An empty Enumerable still returns a non-null
Enumeration, but the first call to
hasMoreElements()
returns false).
public Enumeration getItems(int start,
int end)
start - the enumeration after start items.end - the enumeration after end items.public AVLNode.Cursor getItems(boolean reversedOrder)
backwards - if true, the enumeration
traverses the tree backwards, from the end to the beginning.
public static AVLNode find(AVLNode root,
Object object,
Comparator comparator)
root - the root of the treeobject - The object to search forcomparator - comparison functiongetObject()
equals the object, or null if none was foundpublic String toString()
toString(false, false)toString in class Object
public String toString(boolean printValue,
boolean showThreads)
printValue - if true, include getObject().toString()showThreads - if true, show left/right threading information
public Object clone()
throws CloneNotSupportedException
clone in interface PublicClonableclone in class Object
|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||