23 #ifndef __included_bihash_template_h__ 24 #define __included_bihash_template_h__ 31 #error BIHASH_TYPE not defined 35 #define __bv(a,b) _bv(a,b) 36 #define BV(a) __bv(a,BIHASH_TYPE) 38 #define _bvt(a,b) a##b##_t 39 #define __bvt(a,b) _bvt(a,b) 40 #define BVT(a) __bvt(a,BIHASH_TYPE) 42 typedef struct BV (clib_bihash_value)
46 BVT (clib_bihash_kv) kvp[BIHASH_KVP_PER_PAGE];
47 struct BV (clib_bihash_value) * next_free;
49 }
BVT (clib_bihash_value);
55 #ifndef __defined_clib_bihash_bucket_t__ 56 #define __defined_clib_bihash_bucket_t__ 75 BVT (clib_bihash_value) * values;
77 volatile u32 *writer_lock;
79 BVT (clib_bihash_value) ** working_copies;
80 int *working_copy_lengths;
88 BVT (clib_bihash_value) ** freelists;
108 hp = (
u8 *) h->mheap;
111 ASSERT ((vp - hp) < 0x100000000ULL);
121 BVT (clib_bihash_kv) * add_v,
int is_add);
123 BVT (clib_bihash_kv) * search_v,
124 BVT (clib_bihash_kv) * return_v);
127 void *callback,
void *arg);
133 static inline int BV (clib_bihash_search_inline)
134 (
const BVT (clib_bihash) * h,
BVT (clib_bihash_kv) * kvp)
138 BVT (clib_bihash_value) *
v;
142 hash = BV (clib_bihash_hash) (kvp);
144 bucket_index = hash & (h->nbuckets - 1);
145 b = &h->buckets[bucket_index];
150 hash >>= h->log2_nbuckets;
156 v += (b->linear_search == 0) ? hash & ((1 << b->log2_pages) - 1) : 0;
158 limit <<= b->log2_pages;
160 for (i = 0; i < limit; i++)
162 if (BV (clib_bihash_key_compare) (
v->kvp[
i].key, kvp->key))
171 static inline int BV (clib_bihash_search_inline_2)
172 (
const BVT (clib_bihash) * h,
173 BVT (clib_bihash_kv) * search_key,
BVT (clib_bihash_kv) * valuep)
177 BVT (clib_bihash_value) *
v;
183 hash = BV (clib_bihash_hash) (search_key);
185 bucket_index = hash & (h->nbuckets - 1);
186 b = &h->buckets[bucket_index];
191 hash >>= h->log2_nbuckets;
196 v += (b->linear_search == 0) ? hash & ((1 << b->log2_pages) - 1) : 0;
198 limit <<= b->log2_pages;
200 for (i = 0; i < limit; i++)
202 if (BV (clib_bihash_key_compare) (
v->kvp[
i].key, search_key->key))
u8 pad[3]
log2 (size of the packing page block)
sll srl srl sll sra u16x4 i
#define BIHASH_KVP_PER_PAGE
void clib_bihash_free(clib_bihash *h)
Destroy a bounded index extensible hash table.
Fixed length block allocator.
int clib_bihash_add_del(clib_bihash *h, clib_bihash_kv *add_v, int is_add)
Add or delete a (key,value) pair from a bi-hash table.
static uword clib_bihash_get_offset(clib_bihash *h, void *v)
Get clib mheap offset given a pointer.
void clib_bihash_init(clib_bihash *h, char *name, u32 nbuckets, uword memory_size)
initialize a bounded index extensible hash table
void clib_bihash_foreach_key_value_pair(clib_bihash *h, void *callback, void *arg)
Visit active (key,value) pairs in a bi-hash table.
int clib_bihash_search(clib_bihash *h, clib_bihash_kv *search_v, clib_bihash_kv *return_v)
Search a bi-hash table.
struct clib_bihash_value offset
template key/value backing page structure
static void * clib_bihash_get_value(clib_bihash *h, uword offset)
Get pointer to value page given its clib mheap offset.