19 #ifndef _BOILERPLATE_HASH_H
20 #define _BOILERPLATE_HASH_H
23 #include <boilerplate/list.h>
25 #define HASHSLOTS (1<<8)
38 struct hash_bucket table[HASHSLOTS];
39 int (*compare)(
const struct hashobj *l,
40 const struct hashobj *r);
44 #ifdef CONFIG_XENO_PSHARED
52 struct pvhash_bucket {
53 struct pvlist obj_list;
57 struct pvhash_bucket table[HASHSLOTS];
58 int (*compare)(
const struct pvhashobj *l,
59 const struct pvhashobj *r);
63 #define pvhashobj hashobj
64 #define pvhash_bucket hash_bucket
65 #define pvhash_table hash_table
72 unsigned int __hash_key(
const void *key,
73 size_t length,
unsigned int c);
75 void __hash_init(
void *heap,
struct hash_table *t,
76 int (*compare)(
const struct hashobj *l,
77 const struct hashobj *r));
79 int __hash_enter(
struct hash_table *t,
80 const void *key,
size_t len,
81 struct hashobj *newobj,
int nodup);
83 static inline void hash_init(
struct hash_table *t,
84 int (*compare)(
const struct hashobj *l,
85 const struct hashobj *r))
87 __hash_init(__main_heap, t, compare);
90 void hash_destroy(
struct hash_table *t);
92 static inline int hash_enter(
struct hash_table *t,
93 const void *key,
size_t len,
94 struct hashobj *newobj)
96 return __hash_enter(t, key, len, newobj, 1);
99 static inline int hash_enter_dup(
struct hash_table *t,
100 const void *key,
size_t len,
101 struct hashobj *newobj)
103 return __hash_enter(t, key, len, newobj, 0);
106 int hash_remove(
struct hash_table *t,
struct hashobj *delobj);
108 struct hashobj *hash_search(
struct hash_table *t,
109 const void *key,
size_t len);
111 int hash_walk(
struct hash_table *t,
112 int (*walk)(
struct hash_table *t,
struct hashobj *obj));
114 int hash_compare_strings(
const struct hashobj *l,
115 const struct hashobj *r);
117 #ifdef CONFIG_XENO_PSHARED
119 int __hash_enter_probe(
struct hash_table *t,
120 const void *key,
size_t len,
121 struct hashobj *newobj,
122 int (*probefn)(
struct hashobj *oldobj),
125 int __pvhash_enter(
struct pvhash_table *t,
126 const void *key,
size_t len,
127 struct pvhashobj *newobj,
int nodup);
130 int hash_enter_probe(
struct hash_table *t,
131 const void *key,
size_t len,
132 struct hashobj *newobj,
133 int (*probefn)(
struct hashobj *oldobj))
135 return __hash_enter_probe(t, key, len, newobj, probefn, 1);
139 int hash_enter_probe_dup(
struct hash_table *t,
140 const void *key,
size_t len,
141 struct hashobj *newobj,
142 int (*probefn)(
struct hashobj *oldobj))
144 return __hash_enter_probe(t, key, len, newobj, probefn, 0);
147 struct hashobj *hash_search_probe(
struct hash_table *t,
148 const void *key,
size_t len,
149 int (*probefn)(
struct hashobj *obj));
151 void pvhash_init(
struct pvhash_table *t,
152 int (*compare)(
const struct pvhashobj *l,
153 const struct pvhashobj *r));
156 int pvhash_enter(
struct pvhash_table *t,
157 const void *key,
size_t len,
158 struct pvhashobj *newobj)
160 return __pvhash_enter(t, key, len, newobj, 1);
164 int pvhash_enter_dup(
struct pvhash_table *t,
165 const void *key,
size_t len,
166 struct pvhashobj *newobj)
168 return __pvhash_enter(t, key, len, newobj, 0);
171 int pvhash_remove(
struct pvhash_table *t,
struct pvhashobj *delobj);
173 struct pvhashobj *pvhash_search(
struct pvhash_table *t,
174 const void *key,
size_t len);
176 int pvhash_walk(
struct pvhash_table *t,
177 int (*walk)(
struct pvhash_table *t,
struct pvhashobj *obj));
179 int pvhash_compare_strings(
const struct pvhashobj *l,
180 const struct pvhashobj *r);
183 #define pvhash_init hash_init
184 #define pvhash_enter hash_enter
185 #define pvhash_enter_dup hash_enter_dup
186 #define pvhash_remove hash_remove
187 #define pvhash_search hash_search
188 #define pvhash_walk hash_walk
189 #define pvhash_compare_strings hash_compare_strings