1 #ifndef EL__UTIL_HASH_H
2 #define EL__UTIL_HASH_H
4 #include "util/lists.h"
6 /** This should be hopefully always 32bit at least. I'm not sure what will
7 * happen when this will be of other length, but it should still work ok.
9 typedef unsigned long hash_value_T
;
10 typedef hash_value_T (* hash_func_T
)(unsigned char *key
, unsigned int keylen
, hash_value_T magic
);
13 LIST_HEAD(struct hash_item
);
21 unsigned int width
; /**< Number of bits - hash array must be 2^width long. */
23 struct list_head hash
[1]; /**< Must be at end ! */
26 struct hash
*init_hash8(void);
28 void free_hash(struct hash
**hashp
);
30 struct hash_item
*add_hash_item(struct hash
*hash
, unsigned char *key
, unsigned int keylen
, void *value
);
31 struct hash_item
*get_hash_item(struct hash
*hash
, unsigned char *key
, unsigned int keylen
);
32 void del_hash_item(struct hash
*hash
, struct hash_item
*item
);
35 #define foreach_hash_item(item, hash_table, iterator) \
36 for (iterator = 0; iterator < (1 << (hash_table).width); iterator++) \
37 foreach (item, (hash_table).hash[iterator])