34#ifndef _UTILS_RBTREE_HXX_
35#define _UTILS_RBTREE_HXX_
39#include <sys/tree.hxx>
52template <
typename Key,
typename Value>
class RBTree
73 for (
size_t i = 1; i < nodes; i++)
137 RB_INSERT(tree, &
head, node);
145 RB_REMOVE(tree, &
head, node);
174 return RB_FIND(tree, &
head, &lookup);
182 return RB_MIN(tree, &
head);
190 return RB_MAX(tree, &
head);
199 return RB_NEXT(tree, &
head, node);
209 return node ? RB_NEXT(tree, &
head, node) : node;
218 return RB_PREV(tree, &
head, node);
Though the standard template library includes std::map, commonly implemented as a Red Black tree,...
Node * insert(Key key, Value value)
Insert a node into the tree from pre-allocated Node pool.
struct tree head
tree instance
Key compare(Node *a, Node *b)
Compare two nodes.
Node * next(Key key)
Get the next node in the tree.
void insert(Node *node)
Insert a node into the tree.
RBTree(size_t nodes)
Default Constructor.
Node * first()
Get the first node in the tree.
~RBTree()
Default destructor.
RB_HEAD(tree, Node)
The datagram tree type.
Node * next(Node *node)
Get the next node in the tree.
Node * freeList
list of free nodes
Node * alloc()
Allocate a node from the free list.
void remove(Node *node)
Remove a node from the tree.
Node * previous(Node *node)
Get the previous node in the tree.
RB_GENERATE(tree, Node, entry, compare)
The datagram tree methods.
Node * find(Key key)
Find a node based on its lookup key.
Node * remove(Key key)
Remove a node from the tree.
RBTree()
Default Constructor.
void free(Node *node)
free a node to the free list if it exists.
Node * last()
Get the last node in the tree.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
The metadata for a tree node.
Node()
Default constructor.
Key key
key by which to sort the node
Value value
value of the node
RB_ENTRY(Node) entry
The pointer structure.
Node(Key key, Value value)
Constructor.