|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--structure.RedBlackTree
This class implements a single node of a red-black tree. It is a recursive structure. Relationships between nodes are doubly linked, with parent and child references. Many characteristics of trees may be detected with static methods.
structure.AVLTree
,
BinaryTree
,
BinarySearchTree
Field Summary | |
static RedBlackTree |
EMPTY
the unique empty node; used as children on leaf trees and as empty search trees. |
protected boolean |
isRed
The color of this node - red or black (not red) |
protected RedBlackTree |
left
The left child of this node, or EMPTY |
protected RedBlackTree |
parent
The parent of this node, or null |
protected RedBlackTree |
right
The right child of this node, or EMPTY |
protected Comparable |
value
The value stored in this node |
Constructor Summary | |
protected |
RedBlackTree()
A one-time constructor, for constructing empty trees. |
|
RedBlackTree(Comparable v)
Constructs a red-black tree with no children, value of the node is provided by the user |
Method Summary | |
RedBlackTree |
add(Comparable c)
Add a value to the red black tree, performing neccisary rotations and adjustments. |
protected boolean |
blackConsistency()
Returns true if black properties of tree are correct |
protected void |
blackFixup()
If a black node has just been removed above this; this node is the root of a black-height balanced tree, but the ancestors of this node are shy one black node on this branch. |
protected int |
blackHeight()
Returns the black height of this subtree. |
boolean |
consistency()
Returns true if this node is consistently structured |
protected boolean |
consistentlyBlackHeight(int height)
Checks to make sure that the black height of tree is height |
boolean |
contains(Comparable c)
Determines if the red black search tree contains a value |
int |
depth()
Compute the depth of a node. |
Comparable |
get(Comparable c)
Returns a c-equivalent value from tree, or null. |
private String |
getColor()
Support method for toString() . |
private String |
getHand()
Support method for toString() . |
int |
hashCode()
Computes hash code associated with values of tree. |
protected RedBlackTree |
insert(Comparable c)
Insert a (possibly duplicate) value to red-black search tree |
protected boolean |
isBlack()
Determines if this tree is black. |
boolean |
isEmpty()
Returns true if tree is empty. |
boolean |
isLeftChild()
Determine if this node is a left child |
protected boolean |
isRed()
Determines if this tree is red. |
boolean |
isRightChild()
Determine if this node is a right child |
protected boolean |
isRoot()
Determine if this node is a root. |
Iterator |
iterator()
Returns an in-order iterator over the subtree rooted at this node. |
protected RedBlackTree |
left()
Get left subtree of current node |
protected RedBlackTree |
locate(Comparable c)
Locates a value in the search tree or returns the largest value less than value . |
protected RedBlackTree |
parent()
Get reference to parent of this node |
void |
print()
|
protected boolean |
redConsistency()
Returns true if no red node in subtree has red children |
void |
redFixup()
Takes a red node and, restores the red nodes of the tree to maintain red-black properties if this node has a red parent. |
RedBlackTree |
remove(Comparable c)
Remove an value "equals to" the indicated value. |
protected RedBlackTree |
right()
Get right subtree of current node |
protected RedBlackTree |
root()
Returns reference to root of tree containing n |
protected void |
rotateLeft()
Method to perform a left rotation of tree about this node Node must have a right child. |
protected void |
rotateRight()
Method to perform a right rotation of tree about this node Node must have a left child. |
protected void |
setBlack()
Set this node to be black |
protected void |
setLeft(RedBlackTree newLeft)
Update the left subtree of this node. |
protected void |
setParent(RedBlackTree newParent)
Update the parent of this node |
protected void |
setRed()
Set this node to be a red node |
protected void |
setRed(boolean isRed)
Set this node to be a red or black node, depending on value of isRed . |
protected void |
setRight(RedBlackTree newRight)
Update the right subtree of this node. |
String |
toString()
Returns string representation of red-black tree. |
String |
treeString()
Returns a string representing the tree rooted at this node. |
protected Object |
value()
Returns value associated with this node |
boolean |
wellConnected(RedBlackTree expectedParent)
Returns true iff this tree is well-connected. |
Methods inherited from class java.lang.Object |
|
Field Detail |
protected RedBlackTree left
protected RedBlackTree right
protected RedBlackTree parent
protected Comparable value
protected boolean isRed
public static final RedBlackTree EMPTY
Constructor Detail |
protected RedBlackTree()
public RedBlackTree(Comparable v)
value
- A (possibly null) value to be referenced by nodeMethod Detail |
protected boolean isRed()
protected boolean isBlack()
protected void setRed()
protected void setRed(boolean isRed)
isRed
.protected void setBlack()
protected Object value()
protected RedBlackTree left()
protected RedBlackTree right()
protected RedBlackTree parent()
protected void setParent(RedBlackTree newParent)
newParent
- A reference to the new parent of this nodeprotected void setLeft(RedBlackTree newLeft)
protected void setRight(RedBlackTree newRight)
public boolean isLeftChild()
public boolean isRightChild()
public boolean isEmpty()
protected boolean isRoot()
protected RedBlackTree root()
public int depth()
protected void rotateRight()
protected void rotateLeft()
public RedBlackTree add(Comparable c)
c
- The value to be added to the tree.protected RedBlackTree insert(Comparable c)
c
- The value to be inserted into the tree.public void redFixup()
public RedBlackTree remove(Comparable c)
val
- Value sought to be removed from treeprotected void blackFixup()
public boolean contains(Comparable c)
val
- The value sought. Should be non-nullprotected RedBlackTree locate(Comparable c)
value
.public Comparable get(Comparable c)
c
- The c-equivalent value we are looking for in the tree.public boolean consistency()
protected int blackHeight()
protected boolean redConsistency()
protected boolean blackConsistency()
protected boolean consistentlyBlackHeight(int height)
public boolean wellConnected(RedBlackTree expectedParent)
public void print()
public Iterator iterator()
public int hashCode()
hashCode
in class Object
public String treeString()
private String getHand()
toString()
. Returns R if this is node
is a right child, L if this node is a left child and Root if this
node is the root.private String getColor()
toString()
. Returns Red if this is node
is a red, and Black if this node is black.public String toString()
toString
in class Object
|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |