34#ifndef _UTILS_SYSMAP_HXX_
35#define _UTILS_SYSMAP_HXX_
37#include <sys/tree.hxx>
45template <
typename Key,
typename Value>
class SysMap
208 node->
value = (Value)0;
238 nodes->entry.rbe_left = NULL;
240 for (
size_t i = 1; i <
entries; ++i)
256 Node *node = RB_FIND(tree, &
head, &lookup);
288 Node *node = RB_FIND(tree, &
head, &lookup);
292 RB_REMOVE(tree, &
head, node);
307 RB_REMOVE(tree, &
head, node);
324 memset(node, 0,
sizeof(
Node));
333 memset(node, 0,
sizeof(
Node));
This mimics an std::iterator.
Iterator(const Iterator &it)
Copy constructor.
Node * node
node this iteration is currently indexed to
Iterator(SysMap *context, Node *node)
Constructor.
Iterator & operator++()
Overloaded pre-increement operator.
bool operator!=(const Iterator &it)
Overloaded not equals operator.
Iterator()
Default constructor.
SysMap * m
Context this iteration lives in.
Pair & operator*() const
Overloaded reference operator.
Pair * operator->() const
Overloaded pointer operator.
bool operator==(const Iterator &it)
Overloaded equals operator.
This is an abstraction of BSD sys/tree.h that is meant to mimic the semantics of std::map without hav...
size_t erase(Key key)
Remove a node from the tree.
void free(Node *node)
free a node to the free list if it exists.
Iterator find(const Key &key)
Find an element matching the given key.
SysMap()
Default Constructor which with no mapping entry limit.
size_t max_size()
Maximum theoretical number of elements in the map.
size_t size()
Number of elements currently in the map.
int64_t compare(Node *a, Node *b)
Compare two nodes.
RB_HEAD(tree, Node)
The datagram tree type.
SysMap(size_t entries)
Constructor that limits the number of mappings to a static pool.
size_t entries
total number of entries for this instance
Value & operator[](const Key &key)
Find the index associated with the key and create it if does not exist.
size_t used
total number of entries in use for this instance
Iterator end()
Get an iterator index pointing one past the last element in mapping.
void clear()
Removes all elements in the map.
Iterator begin()
Get an iterator index pointing to the first element in the mapping.
void erase(Iterator it)
Remove a node from the tree.
Node * freeList
list of free nodes
Node * alloc()
Allocate a node from the free list.
Node * nodes
location of pre-allocated Node memory
struct tree head
tree instance
RB_GENERATE(tree, Node, entry, compare)
The datagram tree methods.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
The metadata for a tree node.
Key key
key by which to sort the node
Value value
value of the node
RB_ENTRY(Node) entry
Pointer structure for the tree.
Node()=default
Default constructor.
Key first
mimic first element in an std::pair
Value second
mimic second element in an std::pair