Lines Matching refs:bp
62 bcm_bloom_filter_t *bp = NULL; in bcm_bloom_create() local
69 bp = (*alloc_cb)(cb_ctx, sizeof(*bp)); in bcm_bloom_create()
70 if (!bp) { in bcm_bloom_create()
74 memset(bp, 0, sizeof(*bp)); in bcm_bloom_create()
76 bp->cb_ctx = cb_ctx; in bcm_bloom_create()
77 bp->max_hash = max_hash; in bcm_bloom_create()
78 bp->hash = (*alloc_cb)(cb_ctx, sizeof(*bp->hash) * max_hash); in bcm_bloom_create()
79 if (!bp->hash) { in bcm_bloom_create()
83 memset(bp->hash, 0, sizeof(*bp->hash) * max_hash); in bcm_bloom_create()
86 bp->filter = (*alloc_cb)(cb_ctx, filter_size); in bcm_bloom_create()
87 if (!bp->filter) { in bcm_bloom_create()
91 bp->filter_size = filter_size; in bcm_bloom_create()
92 memset(bp->filter, 0, filter_size); in bcm_bloom_create()
95 *bloom = bp; in bcm_bloom_create()
99 bcm_bloom_destroy(&bp, free_cb); in bcm_bloom_create()
108 bcm_bloom_filter_t *bp; in bcm_bloom_destroy() local
113 bp = *bloom; in bcm_bloom_destroy()
116 if (bp->filter) in bcm_bloom_destroy()
117 (*free_cb)(bp->cb_ctx, bp->filter, bp->filter_size); in bcm_bloom_destroy()
118 if (bp->hash) in bcm_bloom_destroy()
119 (*free_cb)(bp->cb_ctx, bp->hash, in bcm_bloom_destroy()
120 sizeof(*bp->hash) * bp->max_hash); in bcm_bloom_destroy()
121 (*free_cb)(bp->cb_ctx, bp, sizeof(*bp)); in bcm_bloom_destroy()
128 bcm_bloom_add_hash(bcm_bloom_filter_t *bp, bcm_bloom_hash_t hash, uint *idx) in bcm_bloom_add_hash() argument
132 if (!bp || !hash || !idx) in bcm_bloom_add_hash()
135 for (i = 0; i < bp->max_hash; ++i) { in bcm_bloom_add_hash()
136 if (bp->hash[i] == NULL) in bcm_bloom_add_hash()
140 if (i >= bp->max_hash) in bcm_bloom_add_hash()
143 bp->hash[i] = hash; in bcm_bloom_add_hash()
149 bcm_bloom_remove_hash(bcm_bloom_filter_t *bp, uint idx) in bcm_bloom_remove_hash() argument
151 if (!bp) in bcm_bloom_remove_hash()
154 if (idx >= bp->max_hash) in bcm_bloom_remove_hash()
157 bp->hash[idx] = NULL; in bcm_bloom_remove_hash()
162 bcm_bloom_is_member(bcm_bloom_filter_t *bp, in bcm_bloom_is_member() argument
173 if (!bp->filter) /* every one is a member of empty filter */ in bcm_bloom_is_member()
176 buf = bp->filter; in bcm_bloom_is_member()
177 buf_len = bp->filter_size; in bcm_bloom_is_member()
180 for (i = 0; i < bp->max_hash; ++i) { in bcm_bloom_is_member()
182 if (!bp->hash[i]) in bcm_bloom_is_member()
184 pos = (*bp->hash[i])(bp->cb_ctx, i, tag, tag_len); in bcm_bloom_is_member()
198 bcm_bloom_add_member(bcm_bloom_filter_t *bp, const uint8 *tag, uint tag_len) in bcm_bloom_add_member() argument
202 if (!bp || !tag || (tag_len == 0)) in bcm_bloom_add_member()
205 if (!bp->filter) /* validate only */ in bcm_bloom_add_member()
208 for (i = 0; i < bp->max_hash; ++i) { in bcm_bloom_add_member()
210 if (!bp->hash[i]) in bcm_bloom_add_member()
212 pos = (*bp->hash[i])(bp->cb_ctx, i, tag, tag_len); in bcm_bloom_add_member()
213 setbit(bp->filter, pos % BLOOM_BIT_LEN(bp->filter_size)); in bcm_bloom_add_member()
219 int bcm_bloom_get_filter_data(bcm_bloom_filter_t *bp, in bcm_bloom_get_filter_data() argument
222 if (!bp) in bcm_bloom_get_filter_data()
226 *buf_len = bp->filter_size; in bcm_bloom_get_filter_data()
228 if (buf_size < bp->filter_size) in bcm_bloom_get_filter_data()
231 if (bp->filter && bp->filter_size) in bcm_bloom_get_filter_data()
232 memcpy(buf, bp->filter, bp->filter_size); in bcm_bloom_get_filter_data()