34#ifndef _UTILS_LINEARMAP_HXX_
35#define _UTILS_LINEARMAP_HXX_
38#include <sys/tree.hxx>
45template <
typename Key,
typename Value>
class LinearMap
195 for (
size_t i = 0; i <
used; ++i)
197 if (
list[i].key == key)
216 ssize_t i = it.
index;
220 if (i != (ssize_t)--
used)
233 for (
size_t i = 0; i <
used; ++i)
235 if (
list[i].key == key)
271 for (
size_t i = 0; i <
used; ++i)
273 if (
list[i].key == key)
This mimics an std::Iterator.
Iterator(LinearMap *context, size_t index)
Constructor.
bool operator==(const Iterator &it)
Overloaded equals operator.
bool operator!=(const Iterator &it)
Overloaded not equals operator.
Pair & operator*() const
Overloaded reference operator.
Iterator(const Iterator &it)
Copy constructor.
Iterator & operator++()
Overloaded pre-increement operator.
Pair * operator->() const
Overloaded pointer operator.
size_t index
index this iteration is currently indexed to
Iterator()
Default constructor.
LinearMap * m
Context this iteration lives in.
This is an abstraction of BSD sys/tree.h that is meant to mimic the semantics of std::map without hav...
Element * list
list of entries
size_t max_size()
Maximum theoretical number of elements in the map.
LinearMap(size_t entries)
Constructor that limits the number of mappings to a static pool.
Iterator find(const Key &key)
Find an element matching the given key.
void clear()
Removes all elements.
size_t entries
total number of entries for this instance
size_t size()
Number of elements currently in the map.
size_t erase(Key key)
Remove a node from the tree.
Iterator begin()
Get an Iterator index pointing to the first element in the mapping.
Value & operator[](const Key &key)
Find the index associated with the key and create it does not exist.
LinearMap()
Default Constructor which with no mapping entry limit.
void erase(Iterator it)
Remove a node from the tree.
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.
#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++.
Entry element in mapping.
Key key
key by which to sort the node
Value value
value of the node
Key first
mimic first element in an std::pair
Value second
mimic second element in an std::pair