Hash table

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::Iterator GetIterator() 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& other) Swaps the contents of two hash tables

Functions

Capacity

uint32_t Capacity()

Hashtable capacity. Maximum number of entries possible to store in table

PARAMETERS

RETURNS

uint32_t the capacity of the table

Clear

void Clear()

Removes all the entries from the table.

PARAMETERS


dmHashTable

void dmHashTable()

Hashtable with chaining for collision resolution, memcpy-copy semantics (POD types) and 32-bit indicies instead of pointers. (NUMA-friendly)

PARAMETERS


dmHashTable

void dmHashTable()

Constructor. Create an empty hashtable with zero capacity and zero hashtable (buckets)

PARAMETERS


dmHashTable

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

dmHashTable16

void dmHashTable16()

Specialized hash table with uint16_t as keys

PARAMETERS


dmHashTable32

void dmHashTable32()

Specialized hash table with uint32_t as keys

PARAMETERS


dmHashTable64

void dmHashTable64()

Specialized hash table with uint64_t as keys

PARAMETERS


Empty

 Empty()

Check if the table is empty

PARAMETERS

RETURNS

if the table is empty

Erase

void Erase(Key key)

Remove key/value pair.

PARAMETERS

Key key Key to remove

Full

 Full()

Check if the table is full

PARAMETERS

RETURNS

if the table is full

Get

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.

GetIterator

dmHashTable::Iterator GetIterator()

Get an iterator for the key/value pairs

PARAMETERS

RETURNS

dmHashTable::Iterator the iterator

EXAMPLES

dmHashTable<dmhash_t, int>::Iterator iter = ht.GetIterator();
while(iter.Next())
{
    printf("%s: %d\n", dmHashReverseSafe64(iter.GetKey()), iter.GetValue());
}

Iterate

void Iterate( call_back,  context)

Iterate over all entries in table

PARAMETERS

call_back Call-back called for every entry
context Context

OffsetCapacity

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

Put

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

SetCapacity

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

 Size()

Number of entries stored in table. (not the actual hashtable size)

PARAMETERS

RETURNS

of entries.

Swap

void Swap(dmHashTable& other)

Swaps the contents of two hash tables

PARAMETERS

dmHashTable& other the other table

Structs

Iterator

TYPE

struct Iterator

Iterator to the key/value pairs of a hash table

MEMBERS

GetKey()
GetValue()