|
M_hash_u64str_t * | M_hash_u64str_create (size_t size, M_uint8 fillpct, M_uint32 flags) M_MALLOC |
|
void | M_hash_u64str_destroy (M_hash_u64str_t *h) M_FREE(1) |
|
M_bool | M_hash_u64str_insert (M_hash_u64str_t *h, M_uint64 key, const char *value) |
|
M_bool | M_hash_u64str_remove (M_hash_u64str_t *h, M_uint64 key) |
|
M_bool | M_hash_u64str_get (const M_hash_u64str_t *h, M_uint64 key, const char **value) |
|
const char * | M_hash_u64str_get_direct (const M_hash_u64str_t *h, M_uint64 key) |
|
M_bool | M_hash_u64str_is_multi (const M_hash_u64str_t *h) |
|
M_bool | M_hash_u64str_multi_len (const M_hash_u64str_t *h, M_uint64 key, size_t *len) |
|
M_bool | M_hash_u64str_multi_get (const M_hash_u64str_t *h, M_uint64 key, size_t idx, const char **value) |
|
const char * | M_hash_u64str_multi_get_direct (const M_hash_u64str_t *h, M_uint64 key, size_t idx) |
|
M_bool | M_hash_u64str_multi_remove (M_hash_u64str_t *h, M_uint64 key, size_t idx) |
|
M_uint32 | M_hash_u64str_size (const M_hash_u64str_t *h) |
|
size_t | M_hash_u64str_num_collisions (const M_hash_u64str_t *h) |
|
size_t | M_hash_u64str_num_expansions (const M_hash_u64str_t *h) |
|
size_t | M_hash_u64str_num_keys (const M_hash_u64str_t *h) |
|
size_t | M_hash_u64str_enumerate (const M_hash_u64str_t *h, M_hash_u64str_enum_t **hashenum) |
|
M_bool | M_hash_u64str_enumerate_next (const M_hash_u64str_t *h, M_hash_u64str_enum_t *hashenum, M_uint64 *key, const char **value) |
|
void | M_hash_u64str_enumerate_free (M_hash_u64str_enum_t *hashenum) |
|
void | M_hash_u64str_merge (M_hash_u64str_t **dest, M_hash_u64str_t *src) M_FREE(2) |
|
M_hash_u64str_t * | M_hash_u64str_duplicate (const M_hash_u64str_t *h) M_MALLOC |
|
Hashtable, meant for storing uint64 keys and string values.
References to the data will always be read-only. All keys and values will be duplicated by the hashtable.
◆ M_hash_u64str_t
◆ M_hash_u64str_enum_t
◆ M_hash_u64str_flags_t
Flags for controlling the behavior of the hashtable
Enumerator |
---|
M_HASH_U64STR_NONE | Case sensitive single value (new values replace).
|
M_HASH_U64STR_KEYS_ORDERED | Keys should be ordered. Default is insertion order unless the sorted option is specified.
|
M_HASH_U64STR_KEYS_SORTASC | When the keys are ordered sort them using the key_equality function.
|
M_HASH_U64STR_KEYS_SORTDESC | When the keys are ordered sort them using the key_equality function.
|
M_HASH_U64STR_MULTI_VALUE | Allow keys to contain multiple values. Sorted in insertion order another sorting is specified.
|
M_HASH_U64STR_MULTI_SORTASC | Allow keys to contain multiple values sorted in ascending order
|
M_HASH_U64STR_MULTI_SORTDESC | Allow keys to contain multiple values sorted in descending order
|
M_HASH_U64STR_MULTI_GETLAST | When using get and get_direct function get the last value from the list when allowing multiple values. The default is to get the first value.
|
M_HASH_U64STR_MULTI_CASECMP | Value compare is case insensitive.
|
M_HASH_U64STR_STATIC_SEED | Use a static seed for hash function initialization. This greatly reduces the security of the hashtable and removes collision attack protections. This should only be used as a performance optimization when creating millions of hashtables with static data specifically for quick look up. DO NOT use this flag with any hashtable that could store user generated data! Be very careful about duplicating a hashtable that was created with this flag. All duplicates will use the static seed.
|
◆ M_hash_u64str_create()
M_hash_u64str_t * M_hash_u64str_create |
( |
size_t |
size, |
|
|
M_uint8 |
fillpct, |
|
|
M_uint32 |
flags |
|
) |
| |
Create a new hashtable.
The hashtable will pre-allocate an array of buckets based on the rounded up size specified. Any hash collisions will result in those collisions being chained together via a linked list. The hashtable will auto-expand by a power of 2 when the fill percentage specified is reached. All key entries are compared in a case-insensitive fashion, and are duplicated internally. Values are duplicated. Case is preserved for both keys and values.
- Parameters
-
[in] | size | Size of the hash table. If not specified as a power of 2, will be rounded up to the nearest power of 2. |
[in] | fillpct | The maximum fill percentage before the hash table is expanded. If 0 is specified, the hashtable will never expand, otherwise the value must be between 1 and 99 (recommended: 75). |
[in] | flags | M_hash_u64str_flags_t flags for modifying behavior. |
- Returns
- Allocated hashtable.
- See also
- M_hash_u64str_destroy
◆ M_hash_u64str_destroy()
Destroy the hashtable.
- Parameters
-
[in] | h | Hashtable to destroy |
◆ M_hash_u64str_insert()
M_bool M_hash_u64str_insert |
( |
M_hash_u64str_t * |
h, |
|
|
M_uint64 |
key, |
|
|
const char * |
value |
|
) |
| |
Insert an entry into the hashtable.
- Parameters
-
[in,out] | h | Hashtable being referenced. |
[in] | key | Key to insert. |
[in] | value | Value to insert into hashtable. Value will be duplicated, and case will be preserved. May be NULL. |
- Returns
- M_TRUE on success, or M_FALSE on failure.
◆ M_hash_u64str_remove()
Remove an entry from the hashtable.
- Parameters
-
[in,out] | h | Hashtable being referenced. |
[in] | key | Key to remove from the hashtable. |
- Returns
- M_TRUE on success, or M_FALSE if key does not exist.
◆ M_hash_u64str_get()
M_bool M_hash_u64str_get |
( |
const M_hash_u64str_t * |
h, |
|
|
M_uint64 |
key, |
|
|
const char ** |
value |
|
) |
| |
Retrieve the value for a key from the hashtable.
- Parameters
-
[in] | h | Hashtable being referenced. |
[in] | key | Key for value. A NULL or empty string is explicitly disallowed. |
[out] | value | Pointer to value stored in the hashtable. Optional, pass NULL if not needed. |
- Returns
- M_TRUE if value retrieved, M_FALSE if key does not exist.
◆ M_hash_u64str_get_direct()
const char * M_hash_u64str_get_direct |
( |
const M_hash_u64str_t * |
h, |
|
|
M_uint64 |
key |
|
) |
| |
Retrieve the value for a key from the hashtable, and return it directly as the return value.
This cannot be used if you need to differentiate between a key that doesn't exist vs a key with a NULL value.
- Parameters
-
[in] | h | Hashtable being referenced. |
[in] | key | Key for value to retrieve from the hashtable. A NULL or empty string is explicitly disallowed. |
- Returns
- NULL if key doesn't exist or NULL value on file, otherwise the value.
◆ M_hash_u64str_is_multi()
Wether the hashtable a multi value table.
- Parameters
-
[in] | h | Hashtable being referenced. |
- Returns
- M_TRUE if a multi value hashtable.
◆ M_hash_u64str_multi_len()
M_bool M_hash_u64str_multi_len |
( |
const M_hash_u64str_t * |
h, |
|
|
M_uint64 |
key, |
|
|
size_t * |
len |
|
) |
| |
Get the number of values for a given key.
- Parameters
-
[in] | h | Hashtable being referenced. |
[in] | key | Key for value to retrieve. |
[out] | len | The number of values. |
- Returns
- M_TRUE if length is retrieved, M_FALSE if key does not exist.
◆ M_hash_u64str_multi_get()
M_bool M_hash_u64str_multi_get |
( |
const M_hash_u64str_t * |
h, |
|
|
M_uint64 |
key, |
|
|
size_t |
idx, |
|
|
const char ** |
value |
|
) |
| |
Retrieve the value for a key from the given index when supporting muli-values.
- Parameters
-
[in] | h | Hashtable being referenced. |
[in] | key | Key for value to retrieve. |
[in] | idx | The index the value resides at. |
[out] | value | Pointer to value stored. Optional, pass NULL if not needed. |
- Returns
- M_TRUE if value retrieved, M_FALSE if key does not exist
◆ M_hash_u64str_multi_get_direct()
const char * M_hash_u64str_multi_get_direct |
( |
const M_hash_u64str_t * |
h, |
|
|
M_uint64 |
key, |
|
|
size_t |
idx |
|
) |
| |
Retrieve the value for a key from the given index when supporting muli-values.
- Parameters
-
[in] | h | Hashtable being referenced. |
[in] | key | Key for value to retrieve. |
[in] | idx | The index the value resides at. |
- Returns
- M_TRUE if value retrieved, M_FALSE if key does not exist.
◆ M_hash_u64str_multi_remove()
M_bool M_hash_u64str_multi_remove |
( |
M_hash_u64str_t * |
h, |
|
|
M_uint64 |
key, |
|
|
size_t |
idx |
|
) |
| |
Remove a value from the hashtable when supporting muli-values.
If all values have been removed then the key will be removed.
- Parameters
-
[in,out] | h | Hashtable being referenced |
[in] | key | Key for value to retrieve. |
[in] | idx | The index the value resides at. |
- Returns
- M_TRUE if the value was removed, M_FALSE if key does not exist.
◆ M_hash_u64str_size()
Retrieve the current size (number of buckets/slots, not necessarily used).
- Parameters
-
[in] | h | Hashtable being referenced. |
- Returns
- Size of the hashtable.
◆ M_hash_u64str_num_collisions()
Retrieve the number of collisions for hashtable entries that has occurred since creation.
- Parameters
-
[in] | h | Hashtable being referenced. |
- Returns
- Number of collisions.
◆ M_hash_u64str_num_expansions()
Retrieve the number of expansions/rehashes since creation.
- Parameters
-
[in] | h | Hashtable being referenced. |
- Returns
- number of expansions/rehashes.
◆ M_hash_u64str_num_keys()
Retrieve the number of entries in the hashtable.
This is the number of keys stored.
- Parameters
-
[in] | h | Hashtable being referenced. |
- Returns
- number of entries in the hashtable.
◆ M_hash_u64str_enumerate()
Start an enumeration of the keys within the hashtable.
- Parameters
-
[in] | h | Hashtable being referenced. |
[out] | hashenum | Outputs an initialized state variable for starting an enumeration. |
- Returns
- Number of values in the hashtable.
- See also
- M_hash_u64str_enumerate_free
◆ M_hash_u64str_enumerate_next()
Retrieve the next item from a hashtable enumeration.
If multi-value, keys will appear multiple times as each value will be retrieved individually.
- Parameters
-
[in] | h | Hashtable being referenced. |
[in,out] | hashenum | State variable for tracking the enumeration process. |
[out] | key | Value of next enumerated key. Optional, pass NULL if not needed. |
[out] | value | Value of next enumerated value. Optional, pass NULL if not needed. |
- Returns
- M_TRUE if enumeration succeeded, M_FALSE if no more keys.
◆ M_hash_u64str_enumerate_free()
Destroy an enumeration state.
- Parameters
-
[in] | hashenum | Enumeration to destroy. |
◆ M_hash_u64str_merge()
Merge two hashtables together.
The second (src) hashtable will be destroyed automatically upon completion of this function. Any key/value pointers for the hashtable will be directly copied over to the destination hashtable, they will not be duplicated. Any keys which exist in 'dest' that also exist in 'src' will be overwritten by the 'src' value.
If dest and src are multi-value, all values from src will be copied into dest and the values from dest will not be removed. If dest is not multi-value and src is, then only the last value in src will be present in dest. If dest is multi-value and src is not, then the value from src will be added to dest.
- Parameters
-
[in,out] | dest | Pointer by reference to the hashtable receiving the key/value pairs. if dest is NULL, the src address will simply be copied to dest. |
[in,out] | src | Pointer to the hashtable giving up its key/value pairs. |
◆ M_hash_u64str_duplicate()
Duplicate an existing hashtable.
Copying all keys and values.
- Parameters
-
[in] | h | Hashtable to be copied. |
- Returns
- Duplicated hashtable.