html_special(): move va_end() call outside the switch and make variables
[elinks.git] / src / util / hash.h
bloba24794089b6c2b0b40a19dade9187e9e2257453d
2 #ifndef EL__UTIL_HASH_H
3 #define EL__UTIL_HASH_H
5 #include "util/lists.h"
7 /* This should be hopefully always 32bit at least. I'm not sure what will
8 * happen when this will be of other length, but it should still work ok.
9 * --pasky */
10 typedef unsigned long hash_value_T;
11 typedef hash_value_T (* hash_func_T)(unsigned char *key, unsigned int keylen, hash_value_T magic);
13 struct hash_item {
14 LIST_HEAD(struct hash_item);
16 unsigned char *key;
17 unsigned int keylen;
18 void *value;
21 struct hash {
22 unsigned int width; /* Number of bits - hash array must be 2^width long. */
23 hash_func_T func;
24 struct list_head hash[1]; /* Must be at end ! */
27 #define hash_size(n) (1 << (n))
29 struct hash *init_hash(unsigned int width, hash_func_T func);
30 void free_hash(struct hash *hash);
32 struct hash_item *add_hash_item(struct hash *hash, unsigned char *key, unsigned int keylen, void *value);
33 struct hash_item *get_hash_item(struct hash *hash, unsigned char *key, unsigned int keylen);
34 void del_hash_item(struct hash *hash, struct hash_item *item);
35 hash_value_T strhash(unsigned char *k, unsigned int length, hash_value_T initval);
37 #define foreach_hash_item(item, hash_table, iterator) \
38 for (iterator = 0; iterator < hash_size((hash_table).width); iterator++) \
39 foreach (item, (hash_table).hash[iterator])
41 #endif