40 if (Hash == NULL || size == 0) {
62 if (bf->
array == NULL)
70 if (bf->
array != NULL)
81 if (bf->
array != NULL)
90 printf(
"\n------ Counting Bloom Filter Stats ------\n");
91 printf(
"Buckets: %" PRIu32
"\n", bf->
array_size);
92 printf(
"Counter size: %" PRIu32
"\n", bf->
type);
93 printf(
"Memory size: %" PRIu32
" bytes\n", bf->
array_size * bf->
type);
94 printf(
"Hash function pointer: %p\n", bf->
Hash);
96 printf(
"-----------------------------------------\n");
104 if (bf == NULL || data == NULL || datalen == 0)
110 uint8_t *u8 = (uint8_t *)&bf->
array[hash];
113 }
else if (bf->
type == 2) {
114 uint16_t *u16 = (uint16_t *)&bf->
array[hash];
117 }
else if (bf->
type == 4) {
118 uint32_t *u32 = (uint32_t *)&bf->
array[hash];
119 if ((*u32) != 4294967295UL)
132 if (bf == NULL || data == NULL || datalen == 0)
137 printf(
"ERROR: BloomFilterCountingRemove tried to remove data "
138 "that was never added to the set or was already removed.\n");
146 uint8_t *u8 = (uint8_t *)&bf->
array[hash];
150 printf(
"ERROR: BloomFilterCountingRemove tried to decrease a "
151 "counter below zero.\n");
154 }
else if (bf->
type == 2) {
155 uint16_t *u16 = (uint16_t *)&bf->
array[hash];
159 printf(
"ERROR: BloomFilterCountingRemove tried to decrease a "
160 "counter below zero.\n");
163 }
else if (bf->
type == 4) {
164 uint32_t *u32 = (uint32_t *)&bf->
array[hash];
168 printf(
"ERROR: BloomFilterCountingRemove tried to decrease a "
169 "counter below zero.\n");
193 uint8_t *u8 = (uint8_t *)&bf->
array[hash];
198 }
else if (bf->
type == 2) {
199 uint16_t *u16 = (uint16_t *)&bf->
array[hash];
200 if ((*u16) == 0x0000) {
204 }
else if (bf->
type == 4) {
205 uint32_t *u32 = (uint32_t *)&bf->
array[hash];
206 if ((*u32) == 0x00000000) {
221 static uint32_t BloomHash(
const void *data, uint16_t datalen, uint8_t iter, uint32_t hash_size)
223 uint8_t *d = (uint8_t *)data;
227 for (i = 0; i < datalen; i++) {
228 if (i == 0) hash += (((uint32_t)*d++));
229 else if (i == 1) hash += (((uint32_t)*d++) * datalen);
230 else hash *= (((uint32_t)*d++) * i);
233 hash *= (iter + datalen);
238 static int BloomFilterCountingTestInit01 (
void)
249 static int BloomFilterCountingTestInit02 (
void)
259 static int BloomFilterCountingTestInit03 (
void)
266 if (bf->
Hash == BloomHash)
273 static int BloomFilterCountingTestInit04 (
void)
283 static int BloomFilterCountingTestInit05 (
void)
293 static int BloomFilterCountingTestInit06 (
void)
303 static int BloomFilterCountingTestAdd01 (
void)
321 static int BloomFilterCountingTestAdd02 (
void)
339 static int BloomFilterCountingTestFull01 (
void)
344 printf(
"init failed: ");
350 printf(
"first add: ");
374 static int BloomFilterCountingTestFull02 (
void)
397 BloomFilterCountingTestInit01);
399 BloomFilterCountingTestInit02);
401 BloomFilterCountingTestInit03);
403 BloomFilterCountingTestInit04);
405 BloomFilterCountingTestInit05);
407 BloomFilterCountingTestInit06);
410 BloomFilterCountingTestAdd01);
412 BloomFilterCountingTestAdd02);
415 BloomFilterCountingTestFull01);
417 BloomFilterCountingTestFull02);