Hashtable

Namespace: Hashtable Language: C++ Type: Defold C++ File: hashtable.h Source: engine/dlib/src/dmsdk/dlib/hashtable.h Include: dmsdk/dlib/hashtable.h

Hash table

API

Capacity

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

Returns

Clear

Type: FUNCTION Removes all the entries from the table.

dmHashTable

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

Notes

Template Parameters

dmHashTable

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

dmHashTable

Type: FUNCTION Creates a hashtable array with user allocated memory.

Notes

Parameters

dmHashTable16

Type: CLASS Specialized hash table with uint16_t as keys

dmHashTable32

Type: CLASS Specialized hash table with uint32_t as keys

dmHashTable64

Type: CLASS Specialized hash table with uint64_t as keys

Empty

Type: FUNCTION Check if the table is empty

Returns

Erase

Type: FUNCTION Remove key/value pair.

Notes

Parameters

Full

Type: FUNCTION Check if the table is full

Returns

Get

Type: FUNCTION Get pointer to value from key

Parameters

Returns

GetIterator

Type: FUNCTION Get an iterator for the key/value pairs

Returns

Examples

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

Iterate

Type: FUNCTION Iterate over all entries in table

Template Parameters

Parameters

Iterator

Type: STRUCT Iterator to the key/value pairs of a hash table

Members

OffsetCapacity

Type: FUNCTION 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

Put

Type: FUNCTION Put key/value pair in hash table. NOTE: The method will “assert” if the hashtable is full.

Parameters

SetCapacity

Type: FUNCTION Set hashtable capacity. New capacity must be greater or equal to current capacity

Parameters

Size

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

Returns

Swap

Type: FUNCTION Swaps the contents of two hash tables

Parameters