zhangmeng
2024-04-09 2561a007b8d8999a4750046d0cfb3b1ad5af50ac
src/shm/hashtable.h
@@ -5,15 +5,23 @@
#include <functional>
#include <set>
#define MAPSIZE 100
#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);
@@ -24,15 +32,14 @@
void hashtable_put(hashtable_t *hashtable, int key, void *value) ;
bool  hashtable_check_put(hashtable_t *hashtable, int key, void *value, bool overwrite) ;
void *hashtable_remove(hashtable_t *hashtable, int key);
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_lock(hashtable_t *hashtable);
int hashtable_unlock(hashtable_t *hashtable);
int hashtable_get_queue_count(hashtable_t *hashtable) ;
/** 
 * 遍历hash_table
 * @demo 
 * hashtable_foreach(&hashtable, [&](int key, void * value){
 * hashtable_foreach(hashtable, [&](int key, void * value){
 *   printf("%d, %p\n", key, value);
 * });
 *