Main Page | Class Hierarchy | Class List | File List | Class Members

RBTree< Key, Value > Class Template Reference

#include <prom_options.hh>

Collaboration diagram for RBTree< Key, Value >:

Collaboration graph
[legend]
List of all members.

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_

Detailed Description

template<class Key, class Value>
class RBTree< Key, Value >

RBTree is an associative array implemented as a red-black binary tree.

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.


Constructor & Destructor Documentation

template<class Key, class Value>
RBTree< Key, Value >::RBTree  )  [inline]
 

Create an empty RBTree


Member Function Documentation

template<class Key, class Value>
bool RBTree< Key, Value >::containsKey const Key &  key  )  const [inline]
 

find out if tree contains an element indexed by key

template<class Key, class Value>
const Value & RBTree< Key, Value >::get const Key &  key  )  const [inline]
 

get value indexed by key

template<class Key, class Value>
const RBTreeNode< Key, Value > * RBTree< Key, Value >::minimum  )  const [inline, private]
 

get arrays of keys and values

template<class Key, class Value>
bool RBTree< Key, Value >::put const Key &  key,
const Value &  value
[inline]
 

put a new key,value pair in the tree

template<class Key, class Value>
int RBTree< Key, Value >::size  )  const [inline]
 

get number of elements in tree


The documentation for this class was generated from the following file:
Generated on Fri May 21 14:18:24 2004 by doxygen 1.3.7