21 # define _HASHTABLE_H_
129 # ifndef HASHTABLE_NSTATS
153 static inline unsigned mix32(
unsigned int h)
168 # define _JOIN2(x, y) x##y
169 # define _JOIN(x, y) _JOIN2(x, y)
180 # define NAME _JOIN(ENTRY, _hashtable)
183 # define ENTRY_T _JOIN(ENTRY, _t)
184 # define KEY_T _JOIN(KEY, _t)
185 # define MATCH_T _JOIN(MATCH, _t)
187 # define KEY_HASH(k) _JOIN(KEY, _hash)(k)
189 # define MATCH_CMP(m, e) _JOIN(MATCH, _cmp)(m, e)
190 # define _FUNC(f) _JOIN(NAME, f)
195 # define _for_probe(t, k, hk, i, h) \
196 const unsigned mask = t->size - 1;\
197 unsigned hk = KEY_HASH((KEY_T *)k), i, s, h;\
199 for (i = mix32(hk) & mask, s = 0; (h = t->ktable[i]); i = (i + ++s) & mask)
202 # ifndef HASHTABLE_NSTATS
203 # define _stats_inc(c) (c++)
205 # define _stats_inc(c)
220 return _hashtable_new(size);
240 # ifndef HASHTABLE_NSTATS
241 t->find_count = t->match_count = t->hashcmp_count = t->entrycmp_count = 0;
258 if (t->count + 1 == t->size)
260 _for_probe(t, e, he, i, h);
263 return t->etable[i] = e;
280 _stats_inc(t->find_count);
281 _for_probe(t, m, hm, i, he) {
282 _stats_inc(t->hashcmp_count);
284 _stats_inc(t->entrycmp_count);
286 _stats_inc(t->match_count);
310 return _hashtable_iter(i, t);
319 return _hashtable_next(i);
long hashcmp_count
The count of hash compares done.
long match_count
The count of matches found.
#define MATCH_T
The match type.
The hashtable iterator type.
static unsigned mix32(unsigned int h)
MurmurHash3 finalization mix function.
int size
Size of allocated hashtable.
struct hashtable_iter hashtable_iter_t
The hashtable iterator type.
long entrycmp_count
The count of entry compares done.
#define ENTRY_T
The entry type.
unsigned ktable[]
Table of hash keys.
hashtable_t * htable
The hashtable to iterate over.
#define MATCH_CMP(m, e)
The match cmp(m, e) method.
int index
The index to scan from next.
long find_count
The count of finds tried.
struct hashtable hashtable_t
The hashtable type.
void ** etable
Table of pointers to entries.
int count
Number of entries in hashtable.