|
M_hash_strbin_t * | M_hash_strbin_create (size_t size, M_uint8 fillpct, M_uint32 flags) M_MALLOC_ALIASED |
|
void | M_hash_strbin_destroy (M_hash_strbin_t *h) M_FREE(1) |
|
M_bool | M_hash_strbin_insert (M_hash_strbin_t *h, const char *key, const M_uint8 *value, size_t value_len) |
|
M_bool | M_hash_strbin_remove (M_hash_strbin_t *h, const char *key) |
|
M_bool | M_hash_strbin_get (const M_hash_strbin_t *h, const char *key, const M_uint8 **value, size_t *value_len) |
|
const M_uint8 * | M_hash_strbin_get_direct (const M_hash_strbin_t *h, const char *key, size_t *value_len) |
|
M_bool | M_hash_strbin_is_multi (const M_hash_strbin_t *h) |
|
M_bool | M_hash_strbin_multi_len (const M_hash_strbin_t *h, const char *key, size_t *len) |
|
M_bool | M_hash_strbin_multi_get (const M_hash_strbin_t *h, const char *key, size_t idx, const M_uint8 **value, size_t *value_len) |
|
const M_uint8 * | M_hash_strbin_multi_get_direct (const M_hash_strbin_t *h, const char *key, size_t idx, size_t *value_len) |
|
M_bool | M_hash_strbin_multi_remove (M_hash_strbin_t *h, const char *key, size_t idx) |
|
M_uint32 | M_hash_strbin_size (const M_hash_strbin_t *h) |
|
size_t | M_hash_strbin_num_collisions (const M_hash_strbin_t *h) |
|
size_t | M_hash_strbin_num_expansions (const M_hash_strbin_t *h) |
|
size_t | M_hash_strbin_num_keys (const M_hash_strbin_t *h) |
|
size_t | M_hash_strbin_enumerate (const M_hash_strbin_t *h, M_hash_strbin_enum_t **hashenum) |
|
M_bool | M_hash_strbin_enumerate_next (const M_hash_strbin_t *h, M_hash_strbin_enum_t *hashenum, const char **key, const M_uint8 **value, size_t *value_len) |
|
void | M_hash_strbin_enumerate_free (M_hash_strbin_enum_t *hashenum) |
|
void | M_hash_strbin_merge (M_hash_strbin_t **dest, M_hash_strbin_t *src) M_FREE(2) |
|
M_hash_strbin_t * | M_hash_strbin_duplicate (const M_hash_strbin_t *h) M_MALLOC |
|
Hashtable, meant for storing string keys and binary data values.
References to the data will always be read-only. All keys and values will be duplicated by the hashtable.
◆ M_hash_strbin_t
◆ M_hash_strbin_enum_t
◆ M_hash_strbin_flags_t
Flags for controlling the behavior of the hashtable.
Enumerator |
---|
M_HASH_STRBIN_NONE | Case sensitive single value (new values replace).
|
M_HASH_STRBIN_CASECMP | Key compare is case insensitive.
|
M_HASH_STRBIN_KEYS_UPPER | Keys will be upper cased before being inserted. Should be used in conjunction with M_HASH_STRBIN_CASECMP.
|
M_HASH_STRBIN_KEYS_LOWER | Keys will be lower cased before being inserted. Should be used in conjunction with M_HASH_STRBIN_CASECMP.
|
M_HASH_STRBIN_KEYS_ORDERED | Keys should be ordered. Default is insertion order unless the sorted option is specified.
|
M_HASH_STRBIN_KEYS_SORTASC | When the keys are ordered sort them using the key_equality function.
|
M_HASH_STRBIN_KEYS_SORTDESC | When the keys are ordered sort them using the key_equality function.
|
M_HASH_STRBIN_MULTI_VALUE | Allow keys to contain multiple values. Sorted in insertion order another sorting is specified.
|
M_HASH_STRBIN_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_STRBIN_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_strbin_create()
M_hash_strbin_t * M_hash_strbin_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. Values are not duplicated.
- 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_strbin_flags_t flags for modifying behavior. |
- Returns
- Allocated hashtable.
- See also
- M_hash_strbin_destroy
◆ M_hash_strbin_destroy()
Destroy the hashtable.
- Parameters
-
[in] | h | Hashtable to destroy. |
◆ M_hash_strbin_insert()
M_bool M_hash_strbin_insert |
( |
M_hash_strbin_t * |
h, |
|
|
const char * |
key, |
|
|
const M_uint8 * |
value, |
|
|
size_t |
value_len |
|
) |
| |
Insert an entry into the hashtable.
- Parameters
-
[in,out] | h | Hashtable being referenced. |
[in] | key | Key to insert. A NULL or empty string is explicity disallowed. |
[in] | value | Value to insert. Value will be duplicated. May be NULL. |
[in] | value_len | Size of the value being placed into the hash table. |
- Returns
- M_TRUE on success, or M_FALSE on failure.
◆ M_hash_strbin_remove()
Remove an entry from the hashtable.
- Parameters
-
[in,out] | h | Hashtable being referenced. |
[in] | key | Key to remove from the hashtable. A NULL or empty string is explicitly disallowed. |
- Returns
- M_TRUE on success, or M_FALSE if key does not exist.
◆ M_hash_strbin_get()
M_bool M_hash_strbin_get |
( |
const M_hash_strbin_t * |
h, |
|
|
const char * |
key, |
|
|
const M_uint8 ** |
value, |
|
|
size_t * |
value_len |
|
) |
| |
Retrieve the value for a key from the hashtable.
- Parameters
-
[in] | h | Hashtable being referenced. |
[in] | key | Key for value to retrieve from hashtable. A NULL or empty string is explicitly disallowed. |
[out] | value | Pointer to value stored in the hashtable. Optional, pass NULL if not needed. |
[out] | value_len | Size of the value. Optional, pass NULL if not needed. |
- Returns
- M_TRUE if value retrieved, M_FALSE if key does not exist.
◆ M_hash_strbin_get_direct()
const M_uint8 * M_hash_strbin_get_direct |
( |
const M_hash_strbin_t * |
h, |
|
|
const char * |
key, |
|
|
size_t * |
value_len |
|
) |
| |
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. |
[out] | value_len | Size of the value. Optional, pass NULL if not needed. |
- Returns
- NULL if key doesn't exist, otherwise the value.
◆ M_hash_strbin_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_strbin_multi_len()
M_bool M_hash_strbin_multi_len |
( |
const M_hash_strbin_t * |
h, |
|
|
const char * |
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_strbin_multi_get()
M_bool M_hash_strbin_multi_get |
( |
const M_hash_strbin_t * |
h, |
|
|
const char * |
key, |
|
|
size_t |
idx, |
|
|
const M_uint8 ** |
value, |
|
|
size_t * |
value_len |
|
) |
| |
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. A NULL or empty string is explicitly disallowed. |
[in] | idx | The index the value resides at. |
[out] | value | Pointer to value stored. Optional, pass NULL if not needed. |
[out] | value_len | Size of the value. Optional, pass NULL if not needed. |
- Returns
- M_TRUE if value retrieved, M_FALSE if key does not exist.
◆ M_hash_strbin_multi_get_direct()
const M_uint8 * M_hash_strbin_multi_get_direct |
( |
const M_hash_strbin_t * |
h, |
|
|
const char * |
key, |
|
|
size_t |
idx, |
|
|
size_t * |
value_len |
|
) |
| |
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. A NULL or empty string is explicitly disallowed. |
[in] | idx | The index the value resides at. |
[out] | value_len | Size of the value. Optional, pass NULL if not needed. |
- Returns
- M_TRUE if value retrieved, M_FALSE if key does not exist.
◆ M_hash_strbin_multi_remove()
M_bool M_hash_strbin_multi_remove |
( |
M_hash_strbin_t * |
h, |
|
|
const char * |
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_strbin_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_strbin_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_strbin_num_expansions()
Retrieve the number of expansions/rehashes since creation.
- Parameters
-
[in] | h | Hashtable being referenced. |
- Returns
- number of expansions/rehashes.
◆ M_hash_strbin_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_strbin_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_strbin_enumerate_free
◆ M_hash_strbin_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, may be NULL |
[out] | value | Value of next enumerated value. Optional, may be NULL |
[out] | value_len | Size of next enumerated value. |
- Returns
- M_TRUE if enumeration succeeded, M_FALSE if no more keys
◆ M_hash_strbin_enumerate_free()
Destroy an enumeration state.
- Parameters
-
[in] | hashenum | Enumeration to destroy. |
◆ M_hash_strbin_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_strbin_duplicate()
Duplicate an existing hashtable.
Copying all keys and values.
- Parameters
-
[in] | h | Hashtable to be copied. |
- Returns
- Duplicated hashtable.