uthash头文件下载:
uthash/src/uthash.h at master · troydhanson/uthash · GitHub
使用demo
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <uthash.h>
typedef struct
{
int key;
int val;
UT_hash_handle hh;
} myHash;
myHash *g_table = NULL;
void addTable(int key, int val) {
myHash *table;
HASH_FIND_INT(g_table, &key, table); /* id already in the hash? */
if (table == NULL) {
table = (myHash *)malloc(sizeof(myHash));
table->key = key;
table->val = val;
HASH_ADD_INT(g_table, key, table); /* id: name of key field */
}
}
myHash *findTable(int key) {
myHash *res = NULL;
HASH_FIND_INT(g_table, &key, res);
return res;
}