|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure5.RedBlackTree<E>
public class RedBlackTree<E extends java.lang.Comparable<E>>
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
,
structure.BinaryTree
,
structure.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<E> |
left
The left child of this node, or EMPTY |
protected RedBlackTree<E> |
parent
The parent of this node, or null |
protected RedBlackTree<E> |
right
The right child of this node, or EMPTY |
protected E |
value
The value stored in this node |
Constructor Summary | |
---|---|
RedBlackTree()
A one-time constructor, for constructing empty trees. |
|
RedBlackTree(E v)
Constructs a red-black tree with no children, value of the node is provided by the user |
Method Summary | |
---|---|
RedBlackTree<E> |
add(E 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(E c)
Determines if the red black search tree contains a value |
int |
depth()
Compute the depth of a node. |
E |
get(E c)
Returns a c-equivalent value from tree, or null. |
int |
hashCode()
Computes hash code associated with values of tree. |
protected RedBlackTree<E> |
insert(E 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. |
java.util.Iterator<E> |
iterator()
Returns an in-order iterator over the subtree rooted at this node. |
protected RedBlackTree<E> |
left()
Get left subtree of current node |
protected RedBlackTree<E> |
locate(E c)
Locates a value in the search tree or returns the largest value less than value . |
protected RedBlackTree<E> |
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<E> |
remove(E c)
Remove an value "equals to" the indicated value. |
protected RedBlackTree<E> |
right()
Get right subtree of current node |
protected RedBlackTree<E> |
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<E> newLeft)
Update the left subtree of this node. |
protected void |
setParent(RedBlackTree<E> 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<E> newRight)
Update the right subtree of this node. |
java.lang.String |
toString()
Returns string representation of red-black tree. |
java.lang.String |
treeString()
Returns a string representing the tree rooted at this node. |
protected E |
value()
Returns value associated with this node |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected RedBlackTree<E extends java.lang.Comparable<E>> left
protected RedBlackTree<E extends java.lang.Comparable<E>> right
protected RedBlackTree<E extends java.lang.Comparable<E>> parent
protected E extends java.lang.Comparable<E> value
protected boolean isRed
public static final RedBlackTree EMPTY
Constructor Detail |
---|
public RedBlackTree()
public RedBlackTree(E 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 E value()
protected RedBlackTree<E> left()
protected RedBlackTree<E> right()
protected RedBlackTree<E> parent()
protected void setParent(RedBlackTree<E> newParent)
newParent
- A reference to the new parent of this nodeprotected void setLeft(RedBlackTree<E> newLeft)
protected void setRight(RedBlackTree<E> newRight)
public boolean isLeftChild()
public boolean isRightChild()
public boolean isEmpty()
protected boolean isRoot()
protected RedBlackTree<E> root()
public int depth()
protected void rotateRight()
protected void rotateLeft()
public RedBlackTree<E> add(E c)
c
- The value to be added to the tree.
protected RedBlackTree<E> insert(E c)
c
- The value to be inserted into the tree.public void redFixup()
public RedBlackTree<E> remove(E c)
val
- Value sought to be removed from tree
protected void blackFixup()
public boolean contains(E c)
val
- The value sought. Should be non-null
protected RedBlackTree<E> locate(E c)
value
.
public E get(E 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 void print()
public java.util.Iterator<E> iterator()
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String treeString()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |