Hash table
Namespace: | dmHashTable |
Include: | #include <dmsdk/dlib/hashtable.h> |
STRUCTS | |
---|---|
struct Iterator | Iterator to the key/value pairs of a hash table |
FUNCTIONS | |
---|---|
uint32_t Capacity() | Hashtable capacity. Maximum number of entries poss... |
void Clear() | Removes all the entries from the table. |
void dmHashTable() | hashtable |
void dmHashTable() | Constructor. Create an empty hashtable with zero c... |
void dmHashTable( user_allocated, table_size, capacity) | Creates a hashtable array with user allocated memo... |
void dmHashTable16() | Specialized hash table with uint16_t as key... |
void dmHashTable32() | Specialized hash table with uint32_t as key... |
void dmHashTable64() | Specialized hash table with uint64_t as key... |
Empty() | Check if the table is empty |
void Erase(Key key) | Remove key/value pair. |
Full() | Check if the table is full |
T* Get(Key key) | Get pointer to value from key |
dmHashTable |
Get an iterator for the key/value pairs |
void Iterate( call_back, context) | Iterate over all entries in table |
void OffsetCapacity(uint32_t offset) | hashtable offset capacity |
void Put(Key key, const T& value) | Put key/value pair in hash table. NOTE: The method... |
void SetCapacity( table_size, capacity) | Set hashtable capacity. New capacity must be great... |
Size() | Number of entries stored in table. (not the actual... |
void Swap(dmHashTable |
Swaps the contents of two hash tables |
uint32_t Capacity()
Hashtable capacity. Maximum number of entries possible to store in table
PARAMETERS
RETURNS
uint32_t |
the capacity of the table |
void Clear()
Removes all the entries from the table.
PARAMETERS
void dmHashTable()
Hashtable with chaining for collision resolution, memcpy-copy semantics (POD types) and 32-bit indicies instead of pointers. (NUMA-friendly)
PARAMETERS
void dmHashTable()
Constructor. Create an empty hashtable with zero capacity and zero hashtable (buckets)
PARAMETERS
void dmHashTable( user_allocated, table_size, capacity)
Creates a hashtable array with user allocated memory.
PARAMETERS
|
user_allocated |
Pointer to user allocated continous data-block ((table_sizesizeof(uint32_t)) + (capacitysizeof(dmHashTable::Entry)) |
|
table_size |
Hashtable size, ie number of buckets. table_size < 0xffffffff |
|
capacity |
Capacity. capacity < 0xffffffff |
void dmHashTable16()
Specialized hash table with uint16_t as keys
PARAMETERS
void dmHashTable32()
Specialized hash table with uint32_t as keys
PARAMETERS
void dmHashTable64()
Specialized hash table with uint64_t as keys
PARAMETERS
Empty()
Check if the table is empty
PARAMETERS
RETURNS
|
if the table is empty |
void Erase(Key key)
Remove key/value pair.
PARAMETERS
Key |
key |
Key to remove |
Full()
Check if the table is full
PARAMETERS
RETURNS
|
if the table is full |
T* Get(Key key)
Get pointer to value from key
PARAMETERS
Key |
key |
Key |
RETURNS
T* |
Pointer to value. NULL if the key/value pair doesn't exist. |
dmHashTable
Get an iterator for the key/value pairs
PARAMETERS
RETURNS
dmHashTable |
the iterator |
EXAMPLES
dmHashTable<dmhash_t, int>::Iterator iter = ht.GetIterator();
while(iter.Next())
{
printf("%s: %d\n", dmHashReverseSafe64(iter.GetKey()), iter.GetValue());
}
void Iterate( call_back, context)
Iterate over all entries in table
PARAMETERS
|
call_back |
Call-back called for every entry |
|
context |
Context |
void OffsetCapacity(uint32_t offset)
Relative change of capacity Equivalent to SetCapacity(Capacity() + offset). Only allowed for auto-allocated hash tables and will result in a new dynamic allocation
PARAMETERS
uint32_t |
offset |
relative amount of elements to change the capacity |
void Put(Key key, const T& value)
Put key/value pair in hash table. NOTE: The method will "assert" if the hashtable is full.
PARAMETERS
Key |
key |
Key |
const T& |
value |
Value |
void SetCapacity( table_size, capacity)
Set hashtable capacity. New capacity must be greater or equal to current capacity
PARAMETERS
|
table_size |
Hashtable size, ie number of buckets. table_size < 0xffffffff |
|
capacity |
Capacity. capacity < 0xffffffff |
Size()
Number of entries stored in table. (not the actual hashtable size)
PARAMETERS
RETURNS
|
of entries. |
void Swap(dmHashTable
Swaps the contents of two hash tables
PARAMETERS
dmHashTable |
other |
the other table |
TYPE
struct Iterator
Iterator to the key/value pairs of a hash table
MEMBERS
|
GetKey() |
|
|
GetValue() |