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__ 74 BVT (clib_bihash_value) * values;
76 volatile u32 *writer_lock;
78 BVT (clib_bihash_value) ** working_copies;
85 BVT (clib_bihash_value) ** freelists;
105 hp = (
u8 *) h->mheap;
108 ASSERT ((vp - hp) < 0x100000000ULL);
113 (
BVT (clib_bihash) * h,
char *name,
u32 nbuckets,
uword memory_size);
118 BVT (clib_bihash_kv) * add_v,
int is_add);
120 BVT (clib_bihash_kv) * search_v,
121 BVT (clib_bihash_kv) * return_v);
124 void *callback,
void *arg);
130 static inline int BV (clib_bihash_search_inline)
131 (
BVT (clib_bihash) * h,
BVT (clib_bihash_kv) * kvp)
136 BVT (clib_bihash_value) * v;
140 hash = BV (clib_bihash_hash) (kvp);
142 bucket_index = hash & (h->nbuckets - 1);
143 b = &h->buckets[bucket_index];
148 hash >>= h->log2_nbuckets;
151 value_index = hash & ((1 << b->log2_pages) - 1);
156 if (BV (clib_bihash_key_compare) (v->kvp[i].key, kvp->key))
165 static inline int BV (clib_bihash_search_inline_2)
166 (
BVT (clib_bihash) * h,
167 BVT (clib_bihash_kv) * search_key,
BVT (clib_bihash_kv) * valuep)
172 BVT (clib_bihash_value) * v;
178 hash = BV (clib_bihash_hash) (search_key);
180 bucket_index = hash & (h->nbuckets - 1);
181 b = &h->buckets[bucket_index];
186 hash >>= h->log2_nbuckets;
189 value_index = hash & ((1 << b->log2_pages) - 1);
194 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
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.
#define BIHASH_KVP_PER_PAGE
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.