|
Open Model Railroad Network (OpenMRN)
|
Though the standard template library includes std::map, commonly implemented as a Red Black tree, this alternative provides a transparent mechanism for the user to manage all of the memory used by the tree. More...
#include <RBTree.hxx>
Classes | |
| struct | Node |
| The metadata for a tree node. More... | |
Public Member Functions | |
| RBTree () | |
| Default Constructor. | |
| RBTree (size_t nodes) | |
| Default Constructor. | |
| Node * | insert (Key key, Value value) |
| Insert a node into the tree from pre-allocated Node pool. | |
| void | insert (Node *node) |
| Insert a node into the tree. | |
| void | remove (Node *node) |
| Remove a node from the tree. | |
| Node * | remove (Key key) |
| Remove a node from the tree. | |
| Node * | find (Key key) |
| Find a node based on its lookup key. | |
| Node * | first () |
| Get the first node in the tree. | |
| Node * | last () |
| Get the last node in the tree. | |
| Node * | next (Node *node) |
| Get the next node in the tree. | |
| Node * | next (Key key) |
| Get the next node in the tree. | |
| Node * | previous (Node *node) |
| Get the previous node in the tree. | |
| ~RBTree () | |
| Default destructor. | |
Private Member Functions | |
| Node * | alloc () |
| Allocate a node from the free list. | |
| void | free (Node *node) |
| free a node to the free list if it exists. | |
| Key | compare (Node *a, Node *b) |
| Compare two nodes. | |
| RB_HEAD (tree, Node) | |
| The datagram tree type. | |
| RB_GENERATE (tree, Node, entry, compare) | |
| The datagram tree methods. | |
| DISALLOW_COPY_AND_ASSIGN (RBTree) | |
Private Attributes | |
| Node * | freeList |
| list of free nodes | |
| struct tree | head |
| tree instance | |
Though the standard template library includes std::map, commonly implemented as a Red Black tree, this alternative provides a transparent mechanism for the user to manage all of the memory used by the tree.
This allows for a instantiation that does not require the dynamic allocation and freeing of small chunks of memory. Note, there is no mutual exclusion locking mechanism built into this class. Mutual exclusion must be handled by the user as needed.
Definition at line 52 of file RBTree.hxx.
Default Constructor.
Definition at line 57 of file RBTree.hxx.
Default Constructor.
| nodes | number of nodes to statically create and track |
Definition at line 66 of file RBTree.hxx.
Default destructor.
Definition at line 222 of file RBTree.hxx.
Allocate a node from the free list.
Definition at line 230 of file RBTree.hxx.
|
inlineprivate |
Compare two nodes.
| a | first of two nodes to compare |
| b | second of two nodes to compare |
Definition at line 258 of file RBTree.hxx.
Find a node based on its lookup key.
| key | key of node to lookup. |
Definition at line 168 of file RBTree.hxx.
Get the first node in the tree.
Definition at line 180 of file RBTree.hxx.
|
inlineprivate |
free a node to the free list if it exists.
| node | node to free |
Definition at line 244 of file RBTree.hxx.
|
inline |
Insert a node into the tree from pre-allocated Node pool.
| key | key to insert |
| value | value to insert |
Definition at line 112 of file RBTree.hxx.
Get the last node in the tree.
Definition at line 188 of file RBTree.hxx.
Get the next node in the tree.
| key | key of the node to get the next node from |
Definition at line 206 of file RBTree.hxx.
Get the next node in the tree.
| node | node to get the next node from |
Definition at line 197 of file RBTree.hxx.
|
inline |
Get the previous node in the tree.
| node | node to get the previous node from |
Definition at line 216 of file RBTree.hxx.
Remove a node from the tree.
| key | key for the node to remove |
Definition at line 153 of file RBTree.hxx.
Remove a node from the tree.
| node | node to remove |
Definition at line 143 of file RBTree.hxx.
list of free nodes
Definition at line 264 of file RBTree.hxx.
|
private |
tree instance
Definition at line 273 of file RBTree.hxx.