19#ifndef _BOILERPLATE_HASH_H
20#define _BOILERPLATE_HASH_H
23#include <boilerplate/list.h>
25#define HASHSLOTS (1<<8)
28 dref_type(
const void *) key;
29#ifdef CONFIG_XENO_PSHARED
37 struct listobj obj_list;
41 struct hash_bucket table[HASHSLOTS];
45struct hash_operations {
46 int (*compare)(
const void *l,
49#ifdef CONFIG_XENO_PSHARED
50 int (*probe)(
struct hashobj *oldobj);
51 void *(*alloc)(
size_t len);
52 void (*free)(
void *key);
56typedef int (*hash_walk_op)(
struct hash_table *t,
60#ifdef CONFIG_XENO_PSHARED
71 struct pvlistobj obj_list;
75 struct pvhash_bucket table[HASHSLOTS];
79struct pvhash_operations {
80 int (*compare)(
const void *l,
85typedef int (*pvhash_walk_op)(
struct pvhash_table *t,
86 struct pvhashobj *obj,
90#define pvhashobj hashobj
91#define pvhash_bucket hash_bucket
92#define pvhash_table hash_table
93#define pvhash_walk_op hash_walk_op
100unsigned int __hash_key(
const void *key,
101 size_t length,
unsigned int c);
103void __hash_init(
void *heap,
struct hash_table *t);
105int __hash_enter(
struct hash_table *t,
106 const void *key,
size_t len,
107 struct hashobj *newobj,
108 const struct hash_operations *hops,
111static inline void hash_init(
struct hash_table *t)
113 __hash_init(__main_heap, t);
116void hash_destroy(
struct hash_table *t);
118static inline int hash_enter(
struct hash_table *t,
119 const void *key,
size_t len,
120 struct hashobj *newobj,
121 const struct hash_operations *hops)
123 return __hash_enter(t, key, len, newobj, hops, 1);
126static inline int hash_enter_dup(
struct hash_table *t,
127 const void *key,
size_t len,
128 struct hashobj *newobj,
129 const struct hash_operations *hops)
131 return __hash_enter(t, key, len, newobj, hops, 0);
134int hash_remove(
struct hash_table *t,
struct hashobj *delobj,
135 const struct hash_operations *hops);
137struct hashobj *hash_search(
struct hash_table *t,
138 const void *key,
size_t len,
139 const struct hash_operations *hops);
141int hash_walk(
struct hash_table *t,
142 hash_walk_op walk,
void *arg);
144#ifdef CONFIG_XENO_PSHARED
146int __hash_enter_probe(
struct hash_table *t,
147 const void *key,
size_t len,
148 struct hashobj *newobj,
149 const struct hash_operations *hops,
152int __pvhash_enter(
struct pvhash_table *t,
153 const void *key,
size_t len,
154 struct pvhashobj *newobj,
155 const struct pvhash_operations *hops,
159int hash_enter_probe(
struct hash_table *t,
160 const void *key,
size_t len,
161 struct hashobj *newobj,
162 const struct hash_operations *hops)
164 return __hash_enter_probe(t, key, len, newobj, hops, 1);
168int hash_enter_probe_dup(
struct hash_table *t,
169 const void *key,
size_t len,
170 struct hashobj *newobj,
171 const struct hash_operations *hops)
173 return __hash_enter_probe(t, key, len, newobj, hops, 0);
176struct hashobj *hash_search_probe(
struct hash_table *t,
177 const void *key,
size_t len,
178 const struct hash_operations *hops);
180void pvhash_init(
struct pvhash_table *t);
183int pvhash_enter(
struct pvhash_table *t,
184 const void *key,
size_t len,
185 struct pvhashobj *newobj,
186 const struct pvhash_operations *hops)
188 return __pvhash_enter(t, key, len, newobj, hops, 1);
192int pvhash_enter_dup(
struct pvhash_table *t,
193 const void *key,
size_t len,
194 struct pvhashobj *newobj,
195 const struct pvhash_operations *hops)
197 return __pvhash_enter(t, key, len, newobj, hops, 0);
200int pvhash_remove(
struct pvhash_table *t,
struct pvhashobj *delobj,
201 const struct pvhash_operations *hops);
203struct pvhashobj *pvhash_search(
struct pvhash_table *t,
204 const void *key,
size_t len,
205 const struct pvhash_operations *hops);
207int pvhash_walk(
struct pvhash_table *t,
208 pvhash_walk_op walk,
void *arg);
211#define pvhash_init hash_init
212#define pvhash_enter hash_enter
213#define pvhash_enter_dup hash_enter_dup
214#define pvhash_remove hash_remove
215#define pvhash_search hash_search
216#define pvhash_walk hash_walk
217#define pvhash_operations hash_operations