|
void | set (const TKey &p_key, const TData &p_data) |
|
void | set (const Pair &p_pair) |
|
bool | has (const TKey &p_key) const |
|
const TData & | get (const TKey &p_key) const |
|
TData & | get (const TKey &p_key) |
|
_FORCE_INLINE_ TData * | getptr (const TKey &p_key) |
|
_FORCE_INLINE_ const TData * | getptr (const TKey &p_key) const |
|
template<class C > |
_FORCE_INLINE_ TData * | custom_getptr (C p_custom_key, uint32_t p_custom_hash) |
|
template<class C > |
_FORCE_INLINE_ const TData * | custom_getptr (C p_custom_key, uint32_t p_custom_hash) const |
|
bool | erase (const TKey &p_key) |
|
const TData & | operator[] (const TKey &p_key) const |
|
TData & | operator[] (const TKey &p_key) |
|
const TKey * | next (const TKey *p_key) const |
|
unsigned int | size () const |
|
bool | empty () const |
|
void | clear () |
|
void | operator= (const HashMap &p_table) |
|
void | get_key_list (List< TKey > *p_keys) const |
|
| HashMap (const HashMap &p_table) |
|
template<class TKey, class TData, class Hasher = HashMapHahserDefault, uint8_t MIN_HASH_TABLE_POWER = 3, uint8_t RELATIONSHIP = 8>
class HashMap< TKey, TData, Hasher, MIN_HASH_TABLE_POWER, RELATIONSHIP >
- Author
- Juan Linietsky reduz.nosp@m.io@g.nosp@m.mail..nosp@m.com
Implementation of a standard Hashing HashMap, for quick lookups of Data associated with a Key. The implementation provides hashers for the default types, if you need a special kind of hasher, provide your own.
- Parameters
-
TKey | Key, search is based on it, needs to be hasheable. It is unique in this container. |
TData | Data, data associated with the key |
Hasher | Hasher object, needs to provide a valid static hash function for TKey |
MIN_HASH_TABLE_POWER | Miminum size of the hash table, as a power of two. You rarely need to change this parameter. |
RELATIONSHIP | Relationship at which the hash table is resized. if amount of elements is RELATIONSHIP times bigger than the hash table, table is resized to solve this condition. if RELATIONSHIP is zero, table is always MIN_HASH_TABLE_POWER. |
template<class TKey, class TData, class Hasher = HashMapHahserDefault, uint8_t MIN_HASH_TABLE_POWER = 3, uint8_t RELATIONSHIP = 8>
template<class C >
_FORCE_INLINE_ TData* HashMap< TKey, TData, Hasher, MIN_HASH_TABLE_POWER, RELATIONSHIP >::custom_getptr |
( |
C |
p_custom_key, |
|
|
uint32_t |
p_custom_hash |
|
) |
| |
|
inline |
Same as get, except it can return NULL when item was not found. This version is custom, will take a hash and a custom key (that should support operator==()
template<class TKey, class TData, class Hasher = HashMapHahserDefault, uint8_t MIN_HASH_TABLE_POWER = 3, uint8_t RELATIONSHIP = 8>
bool HashMap< TKey, TData, Hasher, MIN_HASH_TABLE_POWER, RELATIONSHIP >::erase |
( |
const TKey & |
p_key | ) |
|
|
inline |
Erase an item, return true if erasing was succesful
template<class TKey, class TData, class Hasher = HashMapHahserDefault, uint8_t MIN_HASH_TABLE_POWER = 3, uint8_t RELATIONSHIP = 8>
const TData& HashMap< TKey, TData, Hasher, MIN_HASH_TABLE_POWER, RELATIONSHIP >::get |
( |
const TKey & |
p_key | ) |
const |
|
inline |
Get a key from data, return a const reference. WARNING: this doesn't check errors, use either getptr and check NULL, or check first with has(key)
template<class TKey, class TData, class Hasher = HashMapHahserDefault, uint8_t MIN_HASH_TABLE_POWER = 3, uint8_t RELATIONSHIP = 8>
_FORCE_INLINE_ TData* HashMap< TKey, TData, Hasher, MIN_HASH_TABLE_POWER, RELATIONSHIP >::getptr |
( |
const TKey & |
p_key | ) |
|
|
inline |
Same as get, except it can return NULL when item was not found. This is mainly used for speed purposes.
template<class TKey, class TData, class Hasher = HashMapHahserDefault, uint8_t MIN_HASH_TABLE_POWER = 3, uint8_t RELATIONSHIP = 8>
const TKey* HashMap< TKey, TData, Hasher, MIN_HASH_TABLE_POWER, RELATIONSHIP >::next |
( |
const TKey * |
p_key | ) |
const |
|
inline |
Get the next key to p_key, and the first key if p_key is null. Returns a pointer to the next key if found, NULL otherwise. Adding/Removing elements while iterating will, of course, have unexpected results, don't do it.
Example:
const TKey *k=NULL;
while( (k=table.next(k)) ) {
print( *k );
}