public class RBTree<K,V> extends BinarySearchTree<K,V> implements Dictionary<K,V>
Modifier and Type | Class and Description |
---|---|
protected static class |
RBTree.RBNode<K,V>
Nested class for the nodes of a red-black tree
|
BinarySearchTree.BSTEntry<K,V>
actionPos, C, numEntries
root, size
Constructor and Description |
---|
RBTree() |
RBTree(java.util.Comparator<K> C) |
Modifier and Type | Method and Description |
---|---|
protected BTPosition<Entry<K,V>> |
createNode(Entry<K,V> element,
BTPosition<Entry<K,V>> parent,
BTPosition<Entry<K,V>> left,
BTPosition<Entry<K,V>> right)
Creates a new tree node.
|
protected boolean |
hasRedChild(Position<Entry<K,V>> position)
Returns whether a node has a red child.
|
Entry<K,V> |
insert(K k,
V x)
Inserts an item into the dictionary and returns the newly
created entry.
|
protected boolean |
isPosRed(Position<Entry<K,V>> position)
Returns whether a node is red.
|
protected Position<Entry<K,V>> |
redChild(Position<Entry<K,V>> position)
Returns a red child of a node.
|
protected void |
remedyDoubleBlack(Position<Entry<K,V>> posR)
Remedies a double black violation at a given node caused by removal.
|
protected void |
remedyDoubleRed(Position<Entry<K,V>> posZ)
Remedies a double red violation at a given node caused by insertion.
|
Entry<K,V> |
remove(Entry<K,V> ent)
Removes and returns the given entry from the dictionary.
|
protected void |
setBlack(Position<Entry<K,V>> position)
Colors a node black.
|
protected void |
setColor(Position<Entry<K,V>> position,
boolean color)
Sets the color of a node.
|
protected void |
setRed(Position<Entry<K,V>> position)
Colors a node red.
|
protected void |
swap(Position<Entry<K,V>> swapPos,
Position<Entry<K,V>> remPos)
Swaps the colors and elements at the two nodes.
|
protected boolean |
swapColor(Position<Entry<K,V>> a,
Position<Entry<K,V>> b)
Swaps the colors of a and b if they are
different and returns whether a was red.
|
addAll, checkEntry, checkKey, entries, entry, find, findAll, insertAtExternal, isEmpty, key, removeExternal, replaceEntry, restructure, size, treeSearch, value
addRoot, attach, checkPosition, children, expandExternal, hasLeft, hasRight, inorderPositions, insertLeft, insertRight, isExternal, isInternal, isRoot, iterator, left, parent, positions, preorderPositions, remove, removeAboveExternal, replace, right, root, sibling, swapElements
public RBTree()
public RBTree(java.util.Comparator<K> C)
protected BTPosition<Entry<K,V>> createNode(Entry<K,V> element, BTPosition<Entry<K,V>> parent, BTPosition<Entry<K,V>> left, BTPosition<Entry<K,V>> right)
createNode
in class LinkedBinaryTree<Entry<K,V>>
public Entry<K,V> insert(K k, V x) throws InvalidKeyException
insert
in interface Dictionary<K,V>
insert
in class BinarySearchTree<K,V>
InvalidKeyException
protected void remedyDoubleRed(Position<Entry<K,V>> posZ)
public Entry<K,V> remove(Entry<K,V> ent) throws InvalidEntryException
remove
in interface Dictionary<K,V>
remove
in class BinarySearchTree<K,V>
InvalidEntryException
protected void remedyDoubleBlack(Position<Entry<K,V>> posR)
protected void setColor(Position<Entry<K,V>> position, boolean color)
color
- true to color the node red, false
to color the node blackprotected Position<Entry<K,V>> redChild(Position<Entry<K,V>> position)
protected boolean hasRedChild(Position<Entry<K,V>> position)
protected boolean swapColor(Position<Entry<K,V>> a, Position<Entry<K,V>> b)