7 #include "expression.h"
8 #include "conf_parser.h"
11 #define HASHTABLE_ORDER 10
12 #define HASHTABLE_SIZE (1<<HASHTABLE_ORDER)
13 #define HASHTABLE_MASK (HASHTABLE_ORDER-1)
15 static struct confnode_list conf_htable[HASHTABLE_SIZE];
17 /* return the hash from name */
18 static inline uint32_t hash_name(const char *name)
21 const unsigned char *c;
23 for (c = (const unsigned char *)name; *c; c++)
24 h += ((((uint32_t)*c) << 4) + (((uint32_t)*c) >> 4)) * 11;
26 return h & HASHTABLE_MASK;
30 * Return the configuration node associated to the given name. If not
33 struct confnode *conf_htable_lookup(const char *name)
36 uint32_t h = hash_name(name);
38 TAILQ_FOREACH(c, &conf_htable[h], hnext) {
39 if (!strncmp(name, c->name, sizeof(c->name)))
46 * Parse a configuration tree and add all the nodes in the hashtable.
48 int conf_htable_fill(struct confnode *root)
51 uint32_t h = hash_name(root->name);
53 TAILQ_INSERT_TAIL(&conf_htable[h], root, hnext);
55 TAILQ_FOREACH(c, &root->children, next) {
62 * Initialize the htable to be empty.
64 int conf_htable_init(void)
68 for (i=0; i<HASHTABLE_SIZE; i++) {
69 TAILQ_INIT(&conf_htable[i]);