#include <stddef.h>
#include <string.h>
#include <stdint.h>
Go to the source code of this file.
|
| void | oa_hash_init (struct oa_hash *ht, struct oa_hash_entry buckets[], const size_t capacity) |
| | Initialize hash table with given buckets array. More...
|
| |
| void | oa_hash_cleanup (struct oa_hash *ht) |
| | Clean up hash table entries and struct. More...
|
| |
| const struct oa_hash_entry * | oa_hash_get_entry (const struct oa_hash *ht, const char key[], const size_t len) |
| | Retrieve entry by key. More...
|
| |
| void * | oa_hash_get (const struct oa_hash *ht, const char key[], const size_t len) |
| | Retrieve value by key (wrapper around oa_hash_get_entry) More...
|
| |
| const struct oa_hash_entry * | oa_hash_set_entry (struct oa_hash *ht, const char key[], const size_t len, void *value) |
| | Insert or update entry. More...
|
| |
| void * | oa_hash_set (struct oa_hash *ht, const char key[], const size_t len, void *value) |
| | Insert or update entry (wrapper around oa_hash_set_entry) More...
|
| |
| int | oa_hash_remove (struct oa_hash *ht, const char key[], const size_t len) |
| | Remove entry by key. More...
|
| |
| struct oa_hash_entry * | oa_hash_rehash (struct oa_hash *ht, struct oa_hash_entry new_buckets[], const size_t new_capacity) |
| | Rehash table to new buckets array. More...
|
| |
◆ OA_HASH_API
| #define OA_HASH_API extern |
◆ __OA_HASH_ATTRS_const
| #define __OA_HASH_ATTRS_const |
Value: const size_t length; \
const size_t capacity; \
Entry holding key-value pair in hash table.
Definition: oa_hash.h:24
entries array
◆ __OA_HASH_ATTRS_mut
| #define __OA_HASH_ATTRS_mut |
Value: size_t length; \
size_t capacity; \
entries array
◆ OA_HASH_ATTRS
| #define OA_HASH_ATTRS |
( |
|
_qualifier | ) |
__OA_HASH_ATTRS_##_qualifier |
can be used to cast to struct oa_hash
◆ oa_hash_entry_state
Hash table entry state.
| Enumerator |
|---|
| OA_HASH_ENTRY_EMPTY | empty entry
|
| OA_HASH_ENTRY_OCCUPIED | occupied entry
|
| OA_HASH_ENTRY_DELETED | deleted entry
|
◆ oa_hash_init()
Initialize hash table with given buckets array.
- Parameters
-
| [out] | ht | the hash table to be initialized |
| [out] | buckets | pre-allocated array of entries |
| [in] | capacity | amount of buckets |
◆ oa_hash_cleanup()
| void oa_hash_cleanup |
( |
struct oa_hash * |
ht | ) |
|
Clean up hash table entries and struct.
- Parameters
-
| [out] | ht | the hash table to be cleaned |
◆ oa_hash_get_entry()
| const struct oa_hash_entry * oa_hash_get_entry |
( |
const struct oa_hash * |
ht, |
|
|
const char |
key[], |
|
|
const size_t |
len |
|
) |
| |
Retrieve entry by key.
- Parameters
-
| [in] | ht | the hash table |
| [in] | key | the key to search for |
| [in] | len | the key length |
- Returns
- entry if found, NULL otherwise
◆ oa_hash_get()
| void * oa_hash_get |
( |
const struct oa_hash * |
ht, |
|
|
const char |
key[], |
|
|
const size_t |
len |
|
) |
| |
Retrieve value by key (wrapper around oa_hash_get_entry)
- Parameters
-
| [in] | ht | the hash table |
| [in] | key | the key to search for |
| [in] | len | the key length |
- Returns
- value if found, NULL otherwise
◆ oa_hash_set_entry()
| const struct oa_hash_entry * oa_hash_set_entry |
( |
struct oa_hash * |
ht, |
|
|
const char |
key[], |
|
|
const size_t |
len, |
|
|
void * |
value |
|
) |
| |
Insert or update entry.
- Parameters
-
| [in,out] | ht | the hash table |
| [in] | key | the key to insert/update |
| [in] | len | the key length |
| [in] | value | the value to be assigned |
- Returns
- entry if successful, or NULL if no space left, in which case oa_hash_rehash() should be called
◆ oa_hash_set()
| void * oa_hash_set |
( |
struct oa_hash * |
ht, |
|
|
const char |
key[], |
|
|
const size_t |
len, |
|
|
void * |
value |
|
) |
| |
Insert or update entry (wrapper around oa_hash_set_entry)
- Parameters
-
| [in,out] | ht | the hash table |
| [in] | key | the key to insert/update |
| [in] | len | the key length |
| [in] | value | the value to be assigned |
- Returns
- value if successful, or NULL if no space left, in which case oa_hash_rehash() should be called
◆ oa_hash_remove()
| int oa_hash_remove |
( |
struct oa_hash * |
ht, |
|
|
const char |
key[], |
|
|
const size_t |
len |
|
) |
| |
Remove entry by key.
- Parameters
-
| [in,out] | ht | the hash table |
| [in] | key | the key to be removed |
| [in] | len | the key length |
- Returns
- 1 if found and removed, 0 otherwise
◆ oa_hash_rehash()
Rehash table to new buckets array.
- Parameters
-
| [in,out] | ht | the hash table |
| [in,out] | new_buckets | the new buckets array |
| [in] | new_capacity | the new buckets capacity |
- Returns
- pointer to old (now unused) bucket if successful, or NULL otherwise