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
Type: FUNCTION Hashtable capacity. Maximum number of entries possible to store in table
Returns
return (uint32_t) - the capacity of the tableType: FUNCTION Removes all the entries from the table.
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
KEYTType: FUNCTION Constructor. Create an empty hashtable with zero capacity and zero hashtable (buckets)
Type: FUNCTION Creates a hashtable array with user allocated memory.
Notes
Parameters
user_allocated (void*) - Pointer to user allocated continous data-block ((table_sizesizeof(uint32_t)) + (capacitysizeof(dmHashTable::Entry))table_size (uint32_t) - Hashtable size, ie number of buckets. table_size < 0xffffffffcapacity (uint32_t) - Capacity. capacity < 0xffffffffType: CLASS Specialized hash table with uint16_t as keys
Type: CLASS Specialized hash table with uint32_t as keys
Type: CLASS Specialized hash table with uint64_t as keys
Type: FUNCTION Check if the table is empty
Returns
true - if the table is emptyType: FUNCTION Remove key/value pair.
Notes
Parameters
key (KEY) - Key to removeType: FUNCTION Check if the table is full
Returns
true - if the table is fullType: FUNCTION Get pointer to value from key
Parameters
key (KEY) - KeyReturns
value (T*) - Pointer to value. NULL if the key/value pair doesn’t exist.Type: FUNCTION Get an iterator for the key/value pairs
Returns
iterator (dmHashTableExamples
dmHashTable::Iterator iter = ht.GetIterator();
while(iter.Next())
{
printf("%s: %d\n", dmHashReverseSafe64(iter.GetKey()), iter.GetValue());
}
Type: FUNCTION Iterate over all entries in table
Template Parameters
CONTEXTParameters
call_back (void*) - Call-back called for every entrycontext (CONTEXT*) - ContextType: STRUCT Iterator to the key/value pairs of a hash table
Members
GetKey()GetValue()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
offset (uint32_t) - relative amount of elements to change the capacityType: FUNCTION Put key/value pair in hash table. NOTE: The method will “assert” if the hashtable is full.
Parameters
key (KEY) - Keyvalue (const T&) - ValueType: FUNCTION Set hashtable capacity. New capacity must be greater or equal to current capacity
Parameters
table_size (uint32_t) - Hashtable size, ie number of buckets. table_size < 0xffffffffcapacity (uint32_t) - Capacity. capacity < 0xffffffffType: FUNCTION Number of entries stored in table. (not the actual hashtable size)
Returns
Number - of entries.Type: FUNCTION Swaps the contents of two hash tables
Parameters
other (dmHashTable<KEY, T>&) - the other table