Lines Matching refs:bp

68 	bcm_bloom_filter_t *bp = NULL;  in bcm_bloom_create()  local
75 bp = (*alloc_cb)(cb_ctx, sizeof(*bp)); in bcm_bloom_create()
76 if (!bp) { in bcm_bloom_create()
81 memset(bp, 0, sizeof(*bp)); in bcm_bloom_create()
82 bp->cb_ctx = cb_ctx; in bcm_bloom_create()
83 bp->max_hash = max_hash; in bcm_bloom_create()
84 bp->hash = (*alloc_cb)(cb_ctx, sizeof(*bp->hash) * max_hash); in bcm_bloom_create()
85 memset(bp->hash, 0, sizeof(*bp->hash) * max_hash); in bcm_bloom_create()
87 if (!bp->hash) { in bcm_bloom_create()
93 bp->filter = (*alloc_cb)(cb_ctx, filter_size); in bcm_bloom_create()
94 if (!bp->filter) { in bcm_bloom_create()
98 bp->filter_size = filter_size; in bcm_bloom_create()
99 memset(bp->filter, 0, filter_size); in bcm_bloom_create()
102 *bloom = bp; in bcm_bloom_create()
106 bcm_bloom_destroy(&bp, free_cb); in bcm_bloom_create()
115 bcm_bloom_filter_t *bp; in bcm_bloom_destroy() local
120 bp = *bloom; in bcm_bloom_destroy()
123 if (bp->filter) in bcm_bloom_destroy()
124 (*free_cb)(bp->cb_ctx, bp->filter, bp->filter_size); in bcm_bloom_destroy()
125 if (bp->hash) in bcm_bloom_destroy()
126 (*free_cb)(bp->cb_ctx, bp->hash, in bcm_bloom_destroy()
127 sizeof(*bp->hash) * bp->max_hash); in bcm_bloom_destroy()
128 (*free_cb)(bp->cb_ctx, bp, sizeof(*bp)); in bcm_bloom_destroy()
135 bcm_bloom_add_hash(bcm_bloom_filter_t *bp, bcm_bloom_hash_t hash, uint *idx) in bcm_bloom_add_hash() argument
139 if (!bp || !hash || !idx) in bcm_bloom_add_hash()
142 for (i = 0; i < bp->max_hash; ++i) { in bcm_bloom_add_hash()
143 if (bp->hash[i] == NULL) in bcm_bloom_add_hash()
147 if (i >= bp->max_hash) in bcm_bloom_add_hash()
150 bp->hash[i] = hash; in bcm_bloom_add_hash()
156 bcm_bloom_remove_hash(bcm_bloom_filter_t *bp, uint idx) in bcm_bloom_remove_hash() argument
158 if (!bp) in bcm_bloom_remove_hash()
161 if (idx >= bp->max_hash) in bcm_bloom_remove_hash()
164 bp->hash[idx] = NULL; in bcm_bloom_remove_hash()
169 bcm_bloom_is_member(bcm_bloom_filter_t *bp, in bcm_bloom_is_member() argument
180 if (!bp->filter) /* every one is a member of empty filter */ in bcm_bloom_is_member()
183 buf = bp->filter; in bcm_bloom_is_member()
184 buf_len = bp->filter_size; in bcm_bloom_is_member()
187 for (i = 0; i < bp->max_hash; ++i) { in bcm_bloom_is_member()
189 if (!bp->hash[i]) in bcm_bloom_is_member()
191 pos = (*bp->hash[i])(bp->cb_ctx, i, tag, tag_len); in bcm_bloom_is_member()
207 bcm_bloom_add_member(bcm_bloom_filter_t *bp, const uint8 *tag, uint tag_len) in bcm_bloom_add_member() argument
211 if (!bp || !tag || (tag_len == 0)) in bcm_bloom_add_member()
214 if (!bp->filter) /* validate only */ in bcm_bloom_add_member()
217 for (i = 0; i < bp->max_hash; ++i) { in bcm_bloom_add_member()
219 if (!bp->hash[i]) in bcm_bloom_add_member()
221 pos = (*bp->hash[i])(bp->cb_ctx, i, tag, tag_len); in bcm_bloom_add_member()
222 setbit(bp->filter, pos % BLOOM_BIT_LEN(bp->filter_size)); in bcm_bloom_add_member()
228 int bcm_bloom_get_filter_data(bcm_bloom_filter_t *bp, in bcm_bloom_get_filter_data() argument
231 if (!bp) in bcm_bloom_get_filter_data()
235 *buf_len = bp->filter_size; in bcm_bloom_get_filter_data()
237 if (buf_size < bp->filter_size) in bcm_bloom_get_filter_data()
240 if (bp->filter && bp->filter_size) in bcm_bloom_get_filter_data()
241 memcpy(buf, bp->filter, bp->filter_size); in bcm_bloom_get_filter_data()