hat-util  0.6.14
Utility library
ht.h
Go to the documentation of this file.
1 #ifndef HAT_HT_H
2 #define HAT_HT_H
3 
11 #include <stddef.h>
12 #include <stdint.h>
13 #include "allocator.h"
14 
15 #define HAT_HT_SUCCESS 0
16 #define HAT_HT_ERROR 1
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
23 typedef struct hat_ht_t hat_ht_t;
24 
26 typedef void *hat_ht_iter_t;
27 
28 
34 hat_ht_t *hat_ht_create(hat_allocator_t *a, size_t avg_count);
35 
40 
46 int hat_ht_resize(hat_ht_t *t, size_t avg_count);
47 
53 
59 
69 int hat_ht_set(hat_ht_t *t, uint8_t *key, size_t key_size, void *value);
70 
79 int hat_ht_set_s(hat_ht_t *t, char *key, void *value);
80 
89 int hat_ht_set_i64(hat_ht_t *t, int64_t key, void *value);
90 
99 int hat_ht_set_u64(hat_ht_t *t, uint64_t key, void *value);
100 
107 void *hat_ht_get(hat_ht_t *t, uint8_t *key, size_t key_size);
108 
114 void *hat_ht_get_s(hat_ht_t *t, char *key);
115 
121 void *hat_ht_get_i64(hat_ht_t *t, int64_t key);
122 
128 void *hat_ht_get_u64(hat_ht_t *t, uint64_t key);
129 
136 int hat_ht_del(hat_ht_t *t, uint8_t *key, size_t key_size);
137 
143 int hat_ht_del_s(hat_ht_t *t, char *key);
144 
150 int hat_ht_del_i64(hat_ht_t *t, int64_t key);
151 
157 int hat_ht_del_u64(hat_ht_t *t, uint64_t key);
158 
168 
175 int hat_ht_iter_key(hat_ht_iter_t i, uint8_t **key, size_t *key_size);
176 
182 int hat_ht_iter_key_s(hat_ht_iter_t i, char **key);
183 
189 int hat_ht_iter_key_i64(hat_ht_iter_t i, int64_t *key);
190 
196 int hat_ht_iter_key_u64(hat_ht_iter_t i, uint64_t *key);
197 
203 int hat_ht_iter_value(hat_ht_iter_t i, void **value);
204 
205 #ifdef __cplusplus
206 }
207 #endif
208 #endif
Memory allocator.
int hat_ht_iter_key(hat_ht_iter_t i, uint8_t **key, size_t *key_size)
Get current key.
size_t hat_ht_count(hat_ht_t *t)
Number of elements in table.
int hat_ht_iter_key_u64(hat_ht_iter_t i, uint64_t *key)
Get current key (uint64_t key)
int hat_ht_set_i64(hat_ht_t *t, int64_t key, void *value)
Set element in table (int64_t key)
int hat_ht_del(hat_ht_t *t, uint8_t *key, size_t key_size)
Delete element from table.
size_t hat_ht_avg_count(hat_ht_t *t)
Initially estimated number of elements in table.
int hat_ht_del_u64(hat_ht_t *t, uint64_t key)
Delete element from table (uint64_t key)
int hat_ht_iter_key_s(hat_ht_iter_t i, char **key)
Get current key (string key)
int hat_ht_del_i64(hat_ht_t *t, int64_t key)
Delete element from table (int64_t key)
hat_ht_t * hat_ht_create(hat_allocator_t *a, size_t avg_count)
Create new hash table.
void * hat_ht_get_s(hat_ht_t *t, char *key)
Get element from table (string key)
void * hat_ht_get(hat_ht_t *t, uint8_t *key, size_t key_size)
Get element from table.
int hat_ht_iter_key_i64(hat_ht_iter_t i, int64_t *key)
Get current key (int64_t key)
int hat_ht_set_s(hat_ht_t *t, char *key, void *value)
Set element in table (string key)
void hat_ht_destroy(hat_ht_t *t)
Destroy hash table.
void * hat_ht_get_u64(hat_ht_t *t, uint64_t key)
Get element from table (uint64_t key)
int hat_ht_set_u64(hat_ht_t *t, uint64_t key, void *value)
Set element in table (uint64_t key)
int hat_ht_set(hat_ht_t *t, uint8_t *key, size_t key_size, void *value)
Set element in table.
int hat_ht_del_s(hat_ht_t *t, char *key)
Delete element from table (string key)
void * hat_ht_get_i64(hat_ht_t *t, int64_t key)
Get element from table (int64_t key)
struct hat_ht_t hat_ht_t
Hash table.
Definition: ht.h:23
hat_ht_iter_t hat_ht_iter_next(hat_ht_t *t, hat_ht_iter_t prev)
Get next iterator position.
int hat_ht_resize(hat_ht_t *t, size_t avg_count)
Reallocate hash table based on new average count.
int hat_ht_iter_value(hat_ht_iter_t i, void **value)
Get current value.
void * hat_ht_iter_t
Hash table iterator.
Definition: ht.h:26
Allocator base struct.
Definition: allocator.h:36