Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
SysMap< Key, Value > Class Template Reference

This is an abstraction of BSD sys/tree.h that is meant to mimic the semantics of std::map without having to link in libstdc++. More...

#include <SysMap.hxx>

Classes

class  Iterator
 This mimics an std::iterator. More...
 
struct  Node
 The metadata for a tree node. More...
 
struct  Pair
 mimic std::pair More...
 

Public Member Functions

 SysMap ()
 Default Constructor which with no mapping entry limit.
 
 SysMap (size_t entries)
 Constructor that limits the number of mappings to a static pool.
 
 ~SysMap ()
 Destructor.
 
Value & operator[] (const Key &key)
 Find the index associated with the key and create it if does not exist.
 
size_t size ()
 Number of elements currently in the map.
 
size_t max_size ()
 Maximum theoretical number of elements in the map.
 
void clear ()
 Removes all elements in the map.
 
Iterator find (const Key &key)
 Find an element matching the given key.
 
Iterator end ()
 Get an iterator index pointing one past the last element in mapping.
 
Iterator begin ()
 Get an iterator index pointing to the first element in the mapping.
 
size_t erase (Key key)
 Remove a node from the tree.
 
void erase (Iterator it)
 Remove a node from the tree.
 

Private Member Functions

Nodealloc ()
 Allocate a node from the free list.
 
void free (Node *node)
 free a node to the free list if it exists.
 
int64_t 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 (SysMap)
 

Private Attributes

size_t entries
 total number of entries for this instance
 
size_t used
 total number of entries in use for this instance
 
NodefreeList
 list of free nodes
 
Nodenodes
 location of pre-allocated Node memory
 
struct tree head
 tree instance
 

Detailed Description

template<typename Key, typename Value>
class SysMap< Key, Value >

This is an abstraction of BSD sys/tree.h that is meant to mimic the semantics of std::map without having to link in libstdc++.

Definition at line 45 of file SysMap.hxx.

Constructor & Destructor Documentation

◆ SysMap() [1/2]

template<typename Key , typename Value >
SysMap< Key, Value >::SysMap ( )
inline

Default Constructor which with no mapping entry limit.

Definition at line 50 of file SysMap.hxx.

◆ SysMap() [2/2]

template<typename Key , typename Value >
SysMap< Key, Value >::SysMap ( size_t  entries)
inline

Constructor that limits the number of mappings to a static pool.

Parameters
entriesnumber of nodes to statically create and track

Definition at line 63 of file SysMap.hxx.

◆ ~SysMap()

template<typename Key , typename Value >
SysMap< Key, Value >::~SysMap ( )
inline

Destructor.

Definition at line 77 of file SysMap.hxx.

Member Function Documentation

◆ alloc()

template<typename Key , typename Value >
Node * SysMap< Key, Value >::alloc ( )
inlineprivate

Allocate a node from the free list.

Returns
newly allocated node, else NULL if no free nodes left

Definition at line 316 of file SysMap.hxx.

◆ begin()

template<typename Key , typename Value >
Iterator SysMap< Key, Value >::begin ( )
inline

Get an iterator index pointing to the first element in the mapping.

Returns
iterator index pointing to the first element in the mapping or to end() if the mapping is empty

Definition at line 273 of file SysMap.hxx.

◆ clear()

template<typename Key , typename Value >
void SysMap< Key, Value >::clear ( )
inline

Removes all elements in the map.

Definition at line 232 of file SysMap.hxx.

◆ compare()

template<typename Key , typename Value >
int64_t SysMap< Key, Value >::compare ( Node a,
Node b 
)
inlineprivate

Compare two nodes.

They type is the largest signed type we know. This is because sys/tree.h only works with signed results on a compare.

Parameters
afirst of two nodes to compare
bsecond of two nodes to compare
Returns
difference between node keys (a->key - b->key)

Definition at line 364 of file SysMap.hxx.

◆ end()

template<typename Key , typename Value >
Iterator SysMap< Key, Value >::end ( )
inline

Get an iterator index pointing one past the last element in mapping.

Returns
iterator index pointing to one past the last element in mapping

Definition at line 264 of file SysMap.hxx.

◆ erase() [1/2]

template<typename Key , typename Value >
void SysMap< Key, Value >::erase ( Iterator  it)
inline

Remove a node from the tree.

Parameters
ititerator index for the element to remove

Definition at line 302 of file SysMap.hxx.

◆ erase() [2/2]

template<typename Key , typename Value >
size_t SysMap< Key, Value >::erase ( Key  key)
inline

Remove a node from the tree.

Parameters
keykey for the element to remove
Returns
number of elements removed

Definition at line 284 of file SysMap.hxx.

◆ find()

template<typename Key , typename Value >
Iterator SysMap< Key, Value >::find ( const Key &  key)
inline

Find an element matching the given key.

Parameters
keykey to search for
Returns
iterator index pointing to key, else iterator end() if not found

Definition at line 252 of file SysMap.hxx.

◆ free()

template<typename Key , typename Value >
void SysMap< Key, Value >::free ( Node node)
inlineprivate

free a node to the free list if it exists.

Parameters
nodenode to free

Definition at line 343 of file SysMap.hxx.

◆ max_size()

template<typename Key , typename Value >
size_t SysMap< Key, Value >::max_size ( )
inline

Maximum theoretical number of elements in the map.

Returns
maximum theoretical number of elements in the map

Definition at line 226 of file SysMap.hxx.

◆ operator[]()

template<typename Key , typename Value >
Value & SysMap< Key, Value >::operator[] ( const Key &  key)
inline

Find the index associated with the key and create it if does not exist.

Parameters
keykey to lookup
Returns
value of the key by reference

Definition at line 200 of file SysMap.hxx.

◆ size()

template<typename Key , typename Value >
size_t SysMap< Key, Value >::size ( )
inline

Number of elements currently in the map.

Returns
number of elements in the map

Definition at line 218 of file SysMap.hxx.

Member Data Documentation

◆ entries

template<typename Key , typename Value >
size_t SysMap< Key, Value >::entries
private

total number of entries for this instance

Definition at line 382 of file SysMap.hxx.

◆ freeList

template<typename Key , typename Value >
Node* SysMap< Key, Value >::freeList
private

list of free nodes

Definition at line 388 of file SysMap.hxx.

◆ head

template<typename Key , typename Value >
struct tree SysMap< Key, Value >::head
private

tree instance

Definition at line 400 of file SysMap.hxx.

◆ nodes

template<typename Key , typename Value >
Node* SysMap< Key, Value >::nodes
private

location of pre-allocated Node memory

Definition at line 391 of file SysMap.hxx.

◆ used

template<typename Key , typename Value >
size_t SysMap< Key, Value >::used
private

total number of entries in use for this instance

Definition at line 385 of file SysMap.hxx.


The documentation for this class was generated from the following file: