127 static size_t binhash_hash(
const void *key, ssize_t len,
size_t size)
137 h = (h << 4U) + *(
unsigned const char *) key++;
138 if ((g = (h & 0xf0000000)) != 0) {
148 #define binhash_link(table, elm) { \
149 BINHASH_INFO **_h = table->data + binhash_hash(elm->key, elm->key_len, table->size);\
151 if ((elm->next = *_h) != 0) \
159 static void binhash_size(
BINHASH *table,
size_t size)
180 binhash_size(table, size < 13 ? 13 : size);
186 static void binhash_grow(
BINHASH *table)
190 ssize_t old_size = table->
size;
194 binhash_size(table, 2 * old_size);
196 while (old_size-- > 0) {
197 for (ht = *h++; ht; ht = next) {
202 myfree((
void *) old_entries);
227 #define KEY_EQ(x,y,l) (((unsigned char *) x)[0] == ((unsigned char *) y)[0] && memcmp(x,y,l) == 0)
230 for (ht = table->
data[binhash_hash(key, key_len, table->
size)]; ht; ht = ht->
next)
243 for (ht = table->
data[binhash_hash(key, key_len, table->
size)]; ht; ht = ht->
next)
257 for (ht = *h; ht; ht = ht->
next) {
268 (*free_fn) (ht->
value);
273 msg_panic(
"binhash_delete: unknown_key: \"%s\"", (
char *) key);
282 ssize_t i = table->
size;
288 for (ht = *h++; ht; ht = next) {
292 (*free_fn) (ht->
value);
307 ssize_t i = table->
size;
312 for (ht = *h++; ht; ht = ht->
next)
329 for (i = 0; i < table->size; i++)
330 for (member = table->data[i]; member != 0; member = member->
next)
331 list[count++] = member;
NORETURN msg_panic(const char *fmt,...)
BINHASH * binhash_create(ssize_t size)
BINHASH_INFO * binhash_enter(BINHASH *table, const void *key, ssize_t key_len, void *value)
BINHASH_INFO * binhash_locate(BINHASH *table, const void *key, ssize_t key_len)
BINHASH_INFO ** binhash_list(BINHASH *table)
void binhash_walk(BINHASH *table, void(*action)(BINHASH_INFO *, void *), void *ptr)
void binhash_free(BINHASH *table, void(*free_fn)(void *))
struct BINHASH_INFO * prev
#define binhash_link(table, elm)
char * mymemdup(const void *ptr, ssize_t len)
struct BINHASH_INFO * next
void * binhash_find(BINHASH *table, const void *key, ssize_t key_len)
void binhash_delete(BINHASH *table, const void *key, ssize_t key_len, void(*free_fn)(void *))
void * mymalloc(ssize_t len)