1 #pragma once 2 3 #include <stdint.h> 4 #include <sys/queue.h> 5 6 typedef uint64_t _key_t; 7 8 struct kvs_entry { 9 _key_t key; 10 void *value; 11 12 TAILQ_ENTRY(kvs_entry) link; 13 }; 14 15 typedef struct kvs_bucket_head { 16 struct kvs_entry *tqh_first; 17 struct kvs_entry **tqh_last; 18 } kvs_bucket_head; 19 20 /* hashtable structure */ 21 typedef struct _kvs_t { 22 int kvs_count ; // count for # entry 23 int num_buckets; 24 int num_entries; 25 26 kvs_bucket_head *kvs_table; 27 kvs_bucket_head kvs_free; 28 struct kvs_entry *kvs_cont; 29 } kvs_t; 30 31 /*functions for hashtable*/ 32 kvs_t * 33 kvs_create(int num_buckets, int num_entries); 34 void 35 kvs_destroy(kvs_t *ht); 36 37 int 38 kvs_insert(kvs_t *ht, _key_t const key, void * const value); 39 void * 40 kvs_remove(kvs_t *ht, _key_t const key); 41 void * 42 kvs_search(kvs_t *ht, _key_t const key); 43