|
Public Member Functions |
| | RBTree () |
|
| RBTree (const RBTree< Key, Value > &other) |
|
const RBTree< Key, Value > & | operator= (const RBTree< Key, Value > &other) |
| int | size () const |
| const Value & | get (const Key &key) const |
|
bool | get (const Key &key, Value &value) const |
| bool | containsKey (const Key &key) const |
| bool | put (const Key &key, const Value &value) |
|
ostream & | print (ostream &os, bool debug=TRUE) const |
Private Member Functions |
| const RBTreeNode< Key, Value > * | minimum () const |
|
const RBTreeNode< Key, Value > * | maximum () const |
|
int | rotateLeft (RBTreeNode< Key, Value > *pivot) |
|
int | rotateRight (RBTreeNode< Key, Value > *pivot) |
|
const RBTreeNode< Key, Value > * | pointerTo (const Key &key) const |
|
RBTreeNode< Key, Value > * | rawInsert (const Key &key, const Value &value) |
Private Attributes |
|
RBTreeNode< Key, Value > * | root_ |
|
int | count_ |
|
Key | cacheKey_ |
|
Value | cacheValue_ |
Red-black trees are described in _Algorithms_ by Cormen, Leiserson, and Rivest. This code closely follows their pseudocode.
To use this code on classes Key and Value: (1) Key and Value must have empty ctors (2) Key must have a less-than comparison operator<(const Key& other) (3) To print an RBTree, Key and value should have stream insertion operators.