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;
87 BVT (clib_bihash_value) ** freelists;
107 hp = (
u8 *) h->mheap;
110 ASSERT ((vp - hp) < 0x100000000ULL);
120 BVT (clib_bihash_kv) * add_v,
int is_add);
122 BVT (clib_bihash_kv) * search_v,
123 BVT (clib_bihash_kv) * return_v);
126 void *callback,
void *arg);
132 static inline int BV (clib_bihash_search_inline)
133 (
const BVT (clib_bihash) *
h,
BVT (clib_bihash_kv) * kvp)
137 BVT (clib_bihash_value) *
v;
141 hash = BV (clib_bihash_hash) (kvp);
143 bucket_index = hash & (h->nbuckets - 1);
144 b = &h->buckets[bucket_index];
149 hash >>= h->log2_nbuckets;
155 v += (b->linear_search == 0) ? hash & ((1 << b->log2_pages) - 1) : 0;
157 limit <<= b->log2_pages;
159 for (i = 0; i < limit; i++)
161 if (BV (clib_bihash_key_compare) (
v->kvp[
i].key, kvp->key))
170 static inline int BV (clib_bihash_search_inline_2)
171 (
const BVT (clib_bihash) *
h,
172 BVT (clib_bihash_kv) * search_key,
BVT (clib_bihash_kv) * valuep)
176 BVT (clib_bihash_value) *
v;
182 hash = BV (clib_bihash_hash) (search_key);
184 bucket_index = hash & (h->nbuckets - 1);
185 b = &h->buckets[bucket_index];
190 hash >>= h->log2_nbuckets;
195 v += (b->linear_search == 0) ? hash & ((1 << b->log2_pages) - 1) : 0;
197 limit <<= b->log2_pages;
199 for (i = 0; i < limit; i++)
201 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.