hat-util
0.6.16
Utility library
|
Hash table. More...
Go to the source code of this file.
Macros | |
#define | HAT_HT_SUCCESS 0 |
#define | HAT_HT_ERROR (-1) |
Typedefs | |
typedef struct hat_ht_t | hat_ht_t |
Hash table. More... | |
typedef void * | hat_ht_iter_t |
Hash table iterator. More... | |
Functions | |
hat_ht_t * | hat_ht_create (hat_allocator_t *a, size_t avg_count) |
Create new hash table. More... | |
void | hat_ht_destroy (hat_ht_t *t) |
Destroy hash table. More... | |
int | hat_ht_resize (hat_ht_t *t, size_t avg_count) |
Reallocate hash table based on new average count. More... | |
size_t | hat_ht_count (hat_ht_t *t) |
Number of elements in table. More... | |
size_t | hat_ht_avg_count (hat_ht_t *t) |
Initially estimated number of elements in table. More... | |
int | hat_ht_set (hat_ht_t *t, uint8_t *key, size_t key_size, void *value) |
Set element in table. More... | |
int | hat_ht_set_s (hat_ht_t *t, char *key, void *value) |
Set element in table (string key) More... | |
int | hat_ht_set_i64 (hat_ht_t *t, int64_t key, void *value) |
Set element in table (int64_t key) More... | |
int | hat_ht_set_u64 (hat_ht_t *t, uint64_t key, void *value) |
Set element in table (uint64_t key) More... | |
void * | hat_ht_get (hat_ht_t *t, uint8_t *key, size_t key_size) |
Get element from table. More... | |
void * | hat_ht_get_s (hat_ht_t *t, char *key) |
Get element from table (string key) More... | |
void * | hat_ht_get_i64 (hat_ht_t *t, int64_t key) |
Get element from table (int64_t key) More... | |
void * | hat_ht_get_u64 (hat_ht_t *t, uint64_t key) |
Get element from table (uint64_t key) More... | |
int | hat_ht_del (hat_ht_t *t, uint8_t *key, size_t key_size) |
Delete element from table. More... | |
int | hat_ht_del_s (hat_ht_t *t, char *key) |
Delete element from table (string key) More... | |
int | hat_ht_del_i64 (hat_ht_t *t, int64_t key) |
Delete element from table (int64_t key) More... | |
int | hat_ht_del_u64 (hat_ht_t *t, uint64_t key) |
Delete element from table (uint64_t key) More... | |
hat_ht_iter_t | hat_ht_iter_next (hat_ht_t *t, hat_ht_iter_t prev) |
Get next iterator position. More... | |
int | hat_ht_iter_key (hat_ht_iter_t i, uint8_t **key, size_t *key_size) |
Get current key. More... | |
int | hat_ht_iter_key_s (hat_ht_iter_t i, char **key) |
Get current key (string key) More... | |
int | hat_ht_iter_key_i64 (hat_ht_iter_t i, int64_t *key) |
Get current key (int64_t key) More... | |
int | hat_ht_iter_key_u64 (hat_ht_iter_t i, uint64_t *key) |
Get current key (uint64_t key) More... | |
int | hat_ht_iter_value (hat_ht_iter_t i, void **value) |
Get current value. More... | |
Hash table.
This hash table implementation stores copies of key data and value pointers.
#define HAT_HT_ERROR (-1) |
#define HAT_HT_SUCCESS 0 |
typedef void* hat_ht_iter_t |
Hash table iterator.
size_t hat_ht_avg_count | ( | hat_ht_t * | t | ) |
Initially estimated number of elements in table.
[in] | t | table |
size_t hat_ht_count | ( | hat_ht_t * | t | ) |
Number of elements in table.
[in] | t | table |
hat_ht_t* hat_ht_create | ( | hat_allocator_t * | a, |
size_t | avg_count | ||
) |
Create new hash table.
[in] | a | allocator |
[in] | avg_count | estimated number of elements in table |
NULL
on failure int hat_ht_del | ( | hat_ht_t * | t, |
uint8_t * | key, | ||
size_t | key_size | ||
) |
Delete element from table.
[in] | t | table |
[in] | key | key |
[in] | key_size | key size |
HAT_HT_SUCCESS
or HAT_HT_ERROR
int hat_ht_del_i64 | ( | hat_ht_t * | t, |
int64_t | key | ||
) |
Delete element from table (int64_t key)
[in] | t | table |
[in] | key | key |
HAT_HT_SUCCESS
or HAT_HT_ERROR
int hat_ht_del_s | ( | hat_ht_t * | t, |
char * | key | ||
) |
Delete element from table (string key)
[in] | t | table |
[in] | key | key |
HAT_HT_SUCCESS
or HAT_HT_ERROR
int hat_ht_del_u64 | ( | hat_ht_t * | t, |
uint64_t | key | ||
) |
Delete element from table (uint64_t key)
[in] | t | table |
[in] | key | key |
HAT_HT_SUCCESS
or HAT_HT_ERROR
void hat_ht_destroy | ( | hat_ht_t * | t | ) |
Destroy hash table.
[in] | t | table |
void* hat_ht_get | ( | hat_ht_t * | t, |
uint8_t * | key, | ||
size_t | key_size | ||
) |
Get element from table.
[in] | t | table |
[in] | key | key |
[in] | key_size | key size |
NULL
on failure void* hat_ht_get_i64 | ( | hat_ht_t * | t, |
int64_t | key | ||
) |
Get element from table (int64_t key)
[in] | t | table |
[in] | key | key |
NULL
on failure void* hat_ht_get_s | ( | hat_ht_t * | t, |
char * | key | ||
) |
Get element from table (string key)
[in] | t | table |
[in] | key | key |
NULL
on failure void* hat_ht_get_u64 | ( | hat_ht_t * | t, |
uint64_t | key | ||
) |
Get element from table (uint64_t key)
[in] | t | table |
[in] | key | key |
NULL
on failure int hat_ht_iter_key | ( | hat_ht_iter_t | i, |
uint8_t ** | key, | ||
size_t * | key_size | ||
) |
Get current key.
[in] | i | iterator |
[out] | key | key |
[out] | key_size | key size |
HAT_HT_SUCCESS
or HAT_HT_ERROR
int hat_ht_iter_key_i64 | ( | hat_ht_iter_t | i, |
int64_t * | key | ||
) |
Get current key (int64_t key)
[in] | i | iterator |
[out] | key | key |
HAT_HT_SUCCESS
or HAT_HT_ERROR
int hat_ht_iter_key_s | ( | hat_ht_iter_t | i, |
char ** | key | ||
) |
Get current key (string key)
[in] | i | iterator |
[out] | key | key |
HAT_HT_SUCCESS
or HAT_HT_ERROR
int hat_ht_iter_key_u64 | ( | hat_ht_iter_t | i, |
uint64_t * | key | ||
) |
Get current key (uint64_t key)
[in] | i | iterator |
[out] | key | key |
HAT_HT_SUCCESS
or HAT_HT_ERROR
hat_ht_iter_t hat_ht_iter_next | ( | hat_ht_t * | t, |
hat_ht_iter_t | prev | ||
) |
Get next iterator position.
[in] | t | table |
[in] | prev | previous iterator position |
NULL
If prev
is NULL
, new iterator points to first entry. If all entries are iterated, NULL
is returned.
int hat_ht_iter_value | ( | hat_ht_iter_t | i, |
void ** | value | ||
) |
Get current value.
[in] | i | iterator |
[out] | value | value |
HAT_HT_SUCCESS
or HAT_HT_ERROR
int hat_ht_resize | ( | hat_ht_t * | t, |
size_t | avg_count | ||
) |
Reallocate hash table based on new average count.
[in] | t | table |
[in] | avg_count | new estimated number of elements in table |
HAT_HT_SUCCESS
or HAT_HT_ERROR
int hat_ht_set | ( | hat_ht_t * | t, |
uint8_t * | key, | ||
size_t | key_size, | ||
void * | value | ||
) |
Set element in table.
[in] | t | table |
[in] | key | key |
[in] | key_size | key size |
[in] | value | value |
HAT_HT_SUCCESS
or HAT_HT_ERROR
If key already exist, value is overridden.
int hat_ht_set_i64 | ( | hat_ht_t * | t, |
int64_t | key, | ||
void * | value | ||
) |
Set element in table (int64_t key)
[in] | t | table |
[in] | key | key |
[in] | value | value |
HAT_HT_SUCCESS
or HAT_HT_ERROR
If key already exist, value is overridden.
int hat_ht_set_s | ( | hat_ht_t * | t, |
char * | key, | ||
void * | value | ||
) |
Set element in table (string key)
[in] | t | table |
[in] | key | key |
[in] | value | value |
HAT_HT_SUCCESS
or HAT_HT_ERROR
If key already exist, value is overridden.
int hat_ht_set_u64 | ( | hat_ht_t * | t, |
uint64_t | key, | ||
void * | value | ||
) |
Set element in table (uint64_t key)
[in] | t | table |
[in] | key | key |
[in] | value | value |
HAT_HT_SUCCESS
or HAT_HT_ERROR
If key already exist, value is overridden.