112 #ifndef HASHTABLE_API_H
113 #define HASHTABLE_API_H
118 #define HASHTABLE_LIB_VERSION "v0.1.1"
121 #if !defined(HASHTABLE_SIZE_T_UINT16) && !defined(HASHTABLE_SIZE_T_UINT32) && !defined(HASHTABLE_SIZE_T_SYS)
122 #define HASHTABLE_SIZE_T_SYS
129 #if defined(HASHTABLE_SIZE_T_UINT16)
131 #elif defined(HASHTABLE_SIZE_T_UINT32)
133 #elif defined(HASHTABLE_SIZE_T_SYS)
136 #error("HASHTABLE_SIZE_T option not defined")
143 #define HASHTABLE_MIN_ARRAY_COUNT (10u)
152 #define HASHTABLE_MIN_BUFFER_SIZE(array_count) \
153 (sizeof(_keyval_pair_table_data_t) + sizeof(_keyval_pair_list_table_t) + \
154 ((array_count) * sizeof(_keyval_pair_list_t)) + \
155 sizeof(_keyval_pair_data_block_t))
205 void *buffer,
size_t buffer_size);
353 #ifdef HASHTABLE_PACKED_STRUCT
354 #define _HASHTABLE_PACKED __attribute__((packed))
356 #define _HASHTABLE_PACKED
364 typedef struct _keyval_pair
366 struct _keyval_pair *next;
370 } _HASHTABLE_PACKED _keyval_pair_t;
378 _keyval_pair_t *head;
379 _keyval_pair_t *tail;
380 } _keyval_pair_list_t;
388 _keyval_pair_list_t freelist;
392 } _keyval_pair_data_block_t;
400 uint32_t array_count;
401 _keyval_pair_list_t table[];
402 } _keyval_pair_list_table_t;
438 _keyval_pair_list_table_t *list_table;
439 _keyval_pair_data_block_t *data_block;
440 uint32_t cursor_array_index;
441 uint32_t cursor_items_traversed;
442 _keyval_pair_t *cursor_item;
443 uint8_t cursor_limit;
444 } _keyval_pair_table_data_t;
int hashtable_default_config(hashtable_config_t *config, size_t buffer_size)
int hashtable_create(hashtable_t *table, const hashtable_config_t *config, void *buffer, size_t buffer_size)
int hashtable_next_item(hashtable_t *table, char **key, hashtable_size_t *key_size, char **value, hashtable_size_t *value_size)
char * hashtable_error_message(void)
int hashtable_remove(hashtable_t *table, const char *key, const hashtable_size_t key_size)
int hashtable_bytes_remaining(hashtable_t *table, size_t *bytes_remaining)
int hashtable_retrieve(hashtable_t *table, const char *key, const hashtable_size_t key_size, char **value, hashtable_size_t *value_size)
int hashtable_reset_cursor(hashtable_t *table)
int hashtable_clear(hashtable_t *table)
int hashtable_insert(hashtable_t *table, const char *key, const hashtable_size_t key_size, const char *value, const hashtable_size_t value_size)
uint32_t(* hashtable_hashfunc_t)(const char *data, const hashtable_size_t size)
Definition: hashtable_api.h:166
size_t hashtable_size_t
Defines the type used to represent the size of keys and values stored in the hashtable.
Definition: hashtable_api.h:134
int hashtable_has_key(hashtable_t *table, const char *key, const hashtable_size_t key_size)
Configuration data for a single hashtable instance.
Definition: hashtable_api.h:173
hashtable_hashfunc_t hash
Hash function to use, must not be NULL.
Definition: hashtable_api.h:174
uint32_t array_count
Number of table array slots, must not be 0.
Definition: hashtable_api.h:175
All data for a single hashtable instance.
Definition: hashtable_api.h:183
uint32_t entry_count
Number of entries in the table.
Definition: hashtable_api.h:185
size_t data_size
Size of data section.
Definition: hashtable_api.h:186
void * table_data
Pointer to buffer for data section.
Definition: hashtable_api.h:187
hashtable_config_t config
Hashtable config data.
Definition: hashtable_api.h:184