一)作者及下载地址
http://troydhanson.github.io/uthash/
在下载的包里,作者提供了丰富的样例,非常好!
二)原理
1)三个结构
typedef struct UT_hash_bucket {
struct UT_hash_handle *hh_head;
unsigned count;
unsigned expand_mult;
} UT_hash_bucket;
typedef struct UT_hash_handle {
struct UT_hash_table *tbl;
void *prev;
void *next;
struct UT_hash_handle *hh_prev;
struct UT_hash_handle *hh_next;
void *key;
unsigned keylen;
unsigned hashv;
} UT_hash_handle;
typedef struct UT_hash_table {
UT_hash_bucket *buckets;
unsigned num_buckets, log2_num_buckets;
unsigned num_items;
struct UT_hash_handle *tail;
ptrdiff_t hho;
unsigned ideal_chain_maxlen;
unsigned nonideal_items;
unsigned ineff_expands, no expand;
uint32_t signature;
uint32_t bloom_sig;
uint8_t *bloom_bv;
uint8_t bloom_nbits;
} UT_hash_table;
二)API
HASH_ADD
HASH_ADD_INT
HASH_ADD_KEYPTR
HASH_ADD_KEYPTR_BYHASHVALUE
HASH_FIND
HASH_FIND_INT
HASH_DEL