#include <rbtree.h>
Public Member Functions | |
| RedBlackTree () | |
| The constructor. | |
| ~RedBlackTree () | |
| The destructor. | |
| bool | insert (Key const &_key, Data const &_rec) |
| Inserts data into the tree. | |
| bool | replace (Key const &_key, Data const &_rec) |
| Change the data at the given node. | |
| bool | erase (Key const &_key) |
| Deletes a node from the tree, specified by the node's key. | |
| bool | erase (Key const &_key, Data const &_rec) |
| Deletes a node from the tree, specified by the node's key and data. | |
| bool | find (Key const &_key, Data &_data) const |
| Finds a node in the tree and copies the data from that node to a specified location. | |
| Data | find (Key const &_key) const |
| Finds a node in the tree and returns the data at that node. | |
| void | empty () |
| Empties the entire tree. | |
| size_t | size () const |
| Indicates the size of the tree. | |
| bool | exists (Key const &_key) const |
| Tests whether a key is in the tree or not. | |
| DArray< Data > * | ConvertToDArray () const |
| Converts the tree data into a linearized DArray. | |
| DArray< Key > * | ConvertIndexToDArray () const |
| Converts the tree keys into a linearized DArray. | |
| size_t | mem_usage () const |
| Returns the overhead caused by the data structure. | |
Protected Member Functions | |
| bool | valid (const RedBlackNode< Key, Data > *_node) const |
| Verifies that a node is valid. | |
Protected Attributes | |
| RedBlackNode< Key, Data > * | rootNode |
| The root node at the top of the tree. | |
| RedBlackNode< Key, Data > * | nullNode |
| The "null" node. Added so we don't need special cases to check for null pointers. | |
| size_t | m_cachedSize |
| The cached size() return value. Changes on each tree modification (insertions and deletions). | |
Private Member Functions | |
| RedBlackTree (const RedBlackTree< Key, Data > &) | |
| Private copy constructor. | |
| RedBlackTree< Key, Data > & | operator= (const RedBlackTree< Key, Data > &) |
| Private assignment operator. | |
Friends | |
| class | RedBlackNode |
Red-black trees are complex, but have good worst-case running time for their operations and are efficient in practice: they can search, insert, and delete in O(log n) time, where n is total number of elements in the tree.
| RedBlackTree | ( | const RedBlackTree< Key, Data > & | ) | [private] |
Private copy constructor.
If your code needs to invoke the copy constructor, you've probably written the code wrong. A tree copy is generally unnecessary, and in cases that it is, it can be achieved by other means.
| DArray<Key>* ConvertIndexToDArray | ( | ) | const |
| DArray<Data>* ConvertToDArray | ( | ) | const |
| void empty | ( | ) | [inline] |
Empties the entire tree.
| bool erase | ( | Key const & | _key, | |
| Data const & | _rec | |||
| ) |
Deletes a node from the tree, specified by the node's key and data.
| _key | The key of the node to delete. | |
| _rec | The data of the node to delete. |
| bool erase | ( | Key const & | _key | ) |
Deletes a node from the tree, specified by the node's key.
| _key | The key of the node to delete. |
| bool exists | ( | Key const & | _key | ) | const |
Tests whether a key is in the tree or not.
| _key | The key of the node to find. |
| Data find | ( | Key const & | _key | ) | const |
Finds a node in the tree and returns the data at that node.
| _key | The key of the node to find. |
| bool find | ( | Key const & | _key, | |
| Data & | _data | |||
| ) | const |
Finds a node in the tree and copies the data from that node to a specified location.
| _key | The key of the node to find. | |
| _data | On return, will contain the data at the node. If not found, _data does not change. |
| bool insert | ( | Key const & | _key, | |
| Data const & | _rec | |||
| ) |
Inserts data into the tree.
| _key | The key of the data. | |
| _rec | The data to insert. |
| size_t mem_usage | ( | ) | const |
Returns the overhead caused by the data structure.
| RedBlackTree<Key, Data>& operator= | ( | const RedBlackTree< Key, Data > & | ) | [private] |
Private assignment operator.
If your code needs to invoke the assignment operator, you've probably written the code wrong. A tree copy is generally unnecessary, and in cases that it is, it can be achieved by other means.
| bool replace | ( | Key const & | _key, | |
| Data const & | _rec | |||
| ) |
Change the data at the given node.
| _key | The key of the node to be modified. | |
| _rec | The data to insert. |
| size_t size | ( | ) | const [inline] |
Indicates the size of the tree.
| bool valid | ( | const RedBlackNode< Key, Data > * | _node | ) | const [inline, protected] |
Verifies that a node is valid.
| _node | A node pointer. |
friend class RedBlackNode [friend] |
1.5.8