#ifndef __HASHTABLE_H__ #define __HASHTABLE_H__ #include #include #include #define START_KEY 1000 #define MAPSIZE 4096 // 创建Queue数量的上限 #define QUEUE_COUNT_LIMIT 300 typedef struct hashtable_t { struct tailq_header_t* array[MAPSIZE]; int mutex; int queueCount; int currentKey; // 当前分配的key // int wlock; // int cond; // size_t readcnt; } hashtable_t; typedef void (*hashtable_foreach_cb)(int key, void *value); void hashtable_init(hashtable_t *hashtable); void hashtable_destroy(hashtable_t *hashtable); void *hashtable_get(hashtable_t *hashtable, int key); void hashtable_put(hashtable_t *hashtable, int key, void *value) ; bool hashtable_check_put(hashtable_t *hashtable, int key, void *value, bool overwrite) ; static inline void _hashtable_remove(hashtable_t *hashtable, int key); void hashtable_remove(hashtable_t *hashtable, int key); void hashtable_removeall(hashtable_t *hashtable); int hashtable_get_queue_count(hashtable_t *hashtable) ; /** * 遍历hash_table * @demo * hashtable_foreach(hashtable, [&](int key, void * value){ * printf("%d, %p\n", key, value); * }); * */ void hashtable_foreach(hashtable_t *hashtable, std::function cb); // void hashtable_printall(hashtable_t *hashtable); int hashtable_alloc_key(hashtable_t *hashtable); std::set * hashtable_keyset(hashtable_t *hashtable) ; #endif