diff options
Diffstat (limited to 'src/util/container_bloomfilter.c')
-rw-r--r-- | src/util/container_bloomfilter.c | 260 |
1 files changed, 129 insertions, 131 deletions
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index a33b619ff..180aab4c3 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c | |||
@@ -89,8 +89,8 @@ struct GNUNET_CONTAINER_BloomFilter | |||
89 | * @return number of bytes used for the data of the bloom filter | 89 | * @return number of bytes used for the data of the bloom filter |
90 | */ | 90 | */ |
91 | size_t | 91 | size_t |
92 | GNUNET_CONTAINER_bloomfilter_get_size (const struct | 92 | GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter |
93 | GNUNET_CONTAINER_BloomFilter *bf) | 93 | *bf) |
94 | { | 94 | { |
95 | if (bf == NULL) | 95 | if (bf == NULL) |
96 | return 0; | 96 | return 0; |
@@ -106,10 +106,10 @@ GNUNET_CONTAINER_bloomfilter_get_size (const struct | |||
106 | */ | 106 | */ |
107 | struct GNUNET_CONTAINER_BloomFilter * | 107 | struct GNUNET_CONTAINER_BloomFilter * |
108 | GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter | 108 | GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter |
109 | *bf) | 109 | *bf) |
110 | { | 110 | { |
111 | return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize, | 111 | return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize, |
112 | bf->addressesPerElement); | 112 | bf->addressesPerElement); |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
@@ -181,7 +181,7 @@ testBit (char *bitArray, unsigned int bitIdx) | |||
181 | */ | 181 | */ |
182 | static void | 182 | static void |
183 | incrementBit (char *bitArray, unsigned int bitIdx, | 183 | incrementBit (char *bitArray, unsigned int bitIdx, |
184 | const struct GNUNET_DISK_FileHandle *fh) | 184 | const struct GNUNET_DISK_FileHandle *fh) |
185 | { | 185 | { |
186 | off_t fileSlot; | 186 | off_t fileSlot; |
187 | unsigned char value; | 187 | unsigned char value; |
@@ -197,25 +197,25 @@ incrementBit (char *bitArray, unsigned int bitIdx, | |||
197 | targetLoc = bitIdx % 2; | 197 | targetLoc = bitIdx % 2; |
198 | 198 | ||
199 | GNUNET_assert (fileSlot == | 199 | GNUNET_assert (fileSlot == |
200 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); | 200 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); |
201 | if (1 != GNUNET_DISK_file_read (fh, &value, 1)) | 201 | if (1 != GNUNET_DISK_file_read (fh, &value, 1)) |
202 | value = 0; | 202 | value = 0; |
203 | low = value & 0xF; | 203 | low = value & 0xF; |
204 | high = (value & (~0xF)) >> 4; | 204 | high = (value & (~0xF)) >> 4; |
205 | 205 | ||
206 | if (targetLoc == 0) | 206 | if (targetLoc == 0) |
207 | { | 207 | { |
208 | if (low < 0xF) | 208 | if (low < 0xF) |
209 | low++; | 209 | low++; |
210 | } | 210 | } |
211 | else | 211 | else |
212 | { | 212 | { |
213 | if (high < 0xF) | 213 | if (high < 0xF) |
214 | high++; | 214 | high++; |
215 | } | 215 | } |
216 | value = ((high << 4) | low); | 216 | value = ((high << 4) | low); |
217 | GNUNET_assert (fileSlot == | 217 | GNUNET_assert (fileSlot == |
218 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); | 218 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); |
219 | GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); | 219 | GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); |
220 | } | 220 | } |
221 | 221 | ||
@@ -229,7 +229,7 @@ incrementBit (char *bitArray, unsigned int bitIdx, | |||
229 | */ | 229 | */ |
230 | static void | 230 | static void |
231 | decrementBit (char *bitArray, unsigned int bitIdx, | 231 | decrementBit (char *bitArray, unsigned int bitIdx, |
232 | const struct GNUNET_DISK_FileHandle *fh) | 232 | const struct GNUNET_DISK_FileHandle *fh) |
233 | { | 233 | { |
234 | off_t fileSlot; | 234 | off_t fileSlot; |
235 | unsigned char value; | 235 | unsigned char value; |
@@ -238,7 +238,7 @@ decrementBit (char *bitArray, unsigned int bitIdx, | |||
238 | unsigned int targetLoc; | 238 | unsigned int targetLoc; |
239 | 239 | ||
240 | if (GNUNET_DISK_handle_invalid (fh)) | 240 | if (GNUNET_DISK_handle_invalid (fh)) |
241 | return; /* cannot decrement! */ | 241 | return; /* cannot decrement! */ |
242 | /* Each char slot in the counter file holds two 4 bit counters */ | 242 | /* Each char slot in the counter file holds two 4 bit counters */ |
243 | fileSlot = bitIdx / 2; | 243 | fileSlot = bitIdx / 2; |
244 | targetLoc = bitIdx % 2; | 244 | targetLoc = bitIdx % 2; |
@@ -250,23 +250,23 @@ decrementBit (char *bitArray, unsigned int bitIdx, | |||
250 | 250 | ||
251 | /* decrement, but once we have reached the max, never go back! */ | 251 | /* decrement, but once we have reached the max, never go back! */ |
252 | if (targetLoc == 0) | 252 | if (targetLoc == 0) |
253 | { | ||
254 | if ((low > 0) && (low < 0xF)) | ||
255 | low--; | ||
256 | if (low == 0) | ||
253 | { | 257 | { |
254 | if ((low > 0) && (low < 0xF)) | 258 | clearBit (bitArray, bitIdx); |
255 | low--; | ||
256 | if (low == 0) | ||
257 | { | ||
258 | clearBit (bitArray, bitIdx); | ||
259 | } | ||
260 | } | 259 | } |
260 | } | ||
261 | else | 261 | else |
262 | { | ||
263 | if ((high > 0) && (high < 0xF)) | ||
264 | high--; | ||
265 | if (high == 0) | ||
262 | { | 266 | { |
263 | if ((high > 0) && (high < 0xF)) | 267 | clearBit (bitArray, bitIdx); |
264 | high--; | ||
265 | if (high == 0) | ||
266 | { | ||
267 | clearBit (bitArray, bitIdx); | ||
268 | } | ||
269 | } | 268 | } |
269 | } | ||
270 | value = ((high << 4) | low); | 270 | value = ((high << 4) | low); |
271 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET); | 271 | GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET); |
272 | GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); | 272 | GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); |
@@ -295,19 +295,19 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size) | |||
295 | GNUNET_DISK_file_seek (fh, 0, GNUNET_DISK_SEEK_SET); | 295 | GNUNET_DISK_file_seek (fh, 0, GNUNET_DISK_SEEK_SET); |
296 | 296 | ||
297 | while (bytesleft > 0) | 297 | while (bytesleft > 0) |
298 | { | ||
299 | if (bytesleft > BUFFSIZE) | ||
298 | { | 300 | { |
299 | if (bytesleft > BUFFSIZE) | 301 | res = GNUNET_DISK_file_write (fh, buffer, BUFFSIZE); |
300 | { | 302 | bytesleft -= BUFFSIZE; |
301 | res = GNUNET_DISK_file_write (fh, buffer, BUFFSIZE); | ||
302 | bytesleft -= BUFFSIZE; | ||
303 | } | ||
304 | else | ||
305 | { | ||
306 | res = GNUNET_DISK_file_write (fh, buffer, bytesleft); | ||
307 | bytesleft = 0; | ||
308 | } | ||
309 | GNUNET_assert (res != GNUNET_SYSERR); | ||
310 | } | 303 | } |
304 | else | ||
305 | { | ||
306 | res = GNUNET_DISK_file_write (fh, buffer, bytesleft); | ||
307 | bytesleft = 0; | ||
308 | } | ||
309 | GNUNET_assert (res != GNUNET_SYSERR); | ||
310 | } | ||
311 | GNUNET_free (buffer); | 311 | GNUNET_free (buffer); |
312 | return GNUNET_OK; | 312 | return GNUNET_OK; |
313 | } | 313 | } |
@@ -325,8 +325,8 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size) | |||
325 | * @return GNUNET_YES to continue, GNUNET_NO to stop early | 325 | * @return GNUNET_YES to continue, GNUNET_NO to stop early |
326 | */ | 326 | */ |
327 | typedef int (*BitIterator) (void *cls, | 327 | typedef int (*BitIterator) (void *cls, |
328 | const struct GNUNET_CONTAINER_BloomFilter * bf, | 328 | const struct GNUNET_CONTAINER_BloomFilter * bf, |
329 | unsigned int bit); | 329 | unsigned int bit); |
330 | 330 | ||
331 | 331 | ||
332 | /** | 332 | /** |
@@ -340,7 +340,7 @@ typedef int (*BitIterator) (void *cls, | |||
340 | */ | 340 | */ |
341 | static void | 341 | static void |
342 | iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, | 342 | iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, |
343 | BitIterator callback, void *arg, const GNUNET_HashCode * key) | 343 | BitIterator callback, void *arg, const GNUNET_HashCode * key) |
344 | { | 344 | { |
345 | GNUNET_HashCode tmp[2]; | 345 | GNUNET_HashCode tmp[2]; |
346 | int bitCount; | 346 | int bitCount; |
@@ -351,27 +351,27 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
351 | tmp[0] = *key; | 351 | tmp[0] = *key; |
352 | round = 0; | 352 | round = 0; |
353 | while (bitCount > 0) | 353 | while (bitCount > 0) |
354 | { | ||
355 | while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) | ||
354 | { | 356 | { |
355 | while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) | 357 | if (GNUNET_YES != |
356 | { | 358 | callback (arg, bf, |
357 | if (GNUNET_YES != | 359 | (((uint32_t *) & tmp[round & 1])[slot]) & |
358 | callback (arg, bf, | 360 | ((bf->bitArraySize * 8) - 1))) |
359 | (((uint32_t *) & tmp[round & 1])[slot]) & | 361 | return; |
360 | ((bf->bitArraySize * 8) - 1))) | 362 | slot++; |
361 | return; | 363 | bitCount--; |
362 | slot++; | 364 | if (bitCount == 0) |
363 | bitCount--; | 365 | break; |
364 | if (bitCount == 0) | ||
365 | break; | ||
366 | } | ||
367 | if (bitCount > 0) | ||
368 | { | ||
369 | GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (GNUNET_HashCode), | ||
370 | &tmp[(round + 1) & 1]); | ||
371 | round++; | ||
372 | slot = 0; | ||
373 | } | ||
374 | } | 366 | } |
367 | if (bitCount > 0) | ||
368 | { | ||
369 | GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (GNUNET_HashCode), | ||
370 | &tmp[(round + 1) & 1]); | ||
371 | round++; | ||
372 | slot = 0; | ||
373 | } | ||
374 | } | ||
375 | } | 375 | } |
376 | 376 | ||
377 | 377 | ||
@@ -384,9 +384,8 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
384 | * @return GNUNET_YES | 384 | * @return GNUNET_YES |
385 | */ | 385 | */ |
386 | static int | 386 | static int |
387 | incrementBitCallback (void *cls, | 387 | incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, |
388 | const struct GNUNET_CONTAINER_BloomFilter *bf, | 388 | unsigned int bit) |
389 | unsigned int bit) | ||
390 | { | 389 | { |
391 | struct GNUNET_CONTAINER_BloomFilter *b = cls; | 390 | struct GNUNET_CONTAINER_BloomFilter *b = cls; |
392 | 391 | ||
@@ -404,9 +403,8 @@ incrementBitCallback (void *cls, | |||
404 | * @return GNUNET_YES | 403 | * @return GNUNET_YES |
405 | */ | 404 | */ |
406 | static int | 405 | static int |
407 | decrementBitCallback (void *cls, | 406 | decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, |
408 | const struct GNUNET_CONTAINER_BloomFilter *bf, | 407 | unsigned int bit) |
409 | unsigned int bit) | ||
410 | { | 408 | { |
411 | struct GNUNET_CONTAINER_BloomFilter *b = cls; | 409 | struct GNUNET_CONTAINER_BloomFilter *b = cls; |
412 | 410 | ||
@@ -425,15 +423,15 @@ decrementBitCallback (void *cls, | |||
425 | */ | 423 | */ |
426 | static int | 424 | static int |
427 | testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | 425 | testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, |
428 | unsigned int bit) | 426 | unsigned int bit) |
429 | { | 427 | { |
430 | int *arg = cls; | 428 | int *arg = cls; |
431 | 429 | ||
432 | if (GNUNET_NO == testBit (bf->bitArray, bit)) | 430 | if (GNUNET_NO == testBit (bf->bitArray, bit)) |
433 | { | 431 | { |
434 | *arg = GNUNET_NO; | 432 | *arg = GNUNET_NO; |
435 | return GNUNET_NO; | 433 | return GNUNET_NO; |
436 | } | 434 | } |
437 | return GNUNET_YES; | 435 | return GNUNET_YES; |
438 | } | 436 | } |
439 | 437 | ||
@@ -451,7 +449,7 @@ testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, | |||
451 | */ | 449 | */ |
452 | struct GNUNET_CONTAINER_BloomFilter * | 450 | struct GNUNET_CONTAINER_BloomFilter * |
453 | GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | 451 | GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, |
454 | unsigned int k) | 452 | unsigned int k) |
455 | { | 453 | { |
456 | struct GNUNET_CONTAINER_BloomFilter *bf; | 454 | struct GNUNET_CONTAINER_BloomFilter *bf; |
457 | char *rbuff; | 455 | char *rbuff; |
@@ -467,32 +465,32 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
467 | ui = 1; | 465 | ui = 1; |
468 | while (ui < size) | 466 | while (ui < size) |
469 | ui *= 2; | 467 | ui *= 2; |
470 | size = ui; /* make sure it's a power of 2 */ | 468 | size = ui; /* make sure it's a power of 2 */ |
471 | 469 | ||
472 | bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); | 470 | bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); |
473 | /* Try to open a bloomfilter file */ | 471 | /* Try to open a bloomfilter file */ |
474 | bf->fh = | 472 | bf->fh = |
475 | GNUNET_DISK_file_open (filename, | 473 | GNUNET_DISK_file_open (filename, |
476 | GNUNET_DISK_OPEN_READWRITE | | 474 | GNUNET_DISK_OPEN_READWRITE | |
477 | GNUNET_DISK_OPEN_CREATE, | 475 | GNUNET_DISK_OPEN_CREATE, |
478 | GNUNET_DISK_PERM_USER_READ | | 476 | GNUNET_DISK_PERM_USER_READ | |
479 | GNUNET_DISK_PERM_USER_WRITE); | 477 | GNUNET_DISK_PERM_USER_WRITE); |
480 | if (NULL == bf->fh) | 478 | if (NULL == bf->fh) |
481 | { | 479 | { |
482 | GNUNET_free (bf); | 480 | GNUNET_free (bf); |
483 | return NULL; | 481 | return NULL; |
484 | } | 482 | } |
485 | bf->filename = GNUNET_strdup (filename); | 483 | bf->filename = GNUNET_strdup (filename); |
486 | /* Alloc block */ | 484 | /* Alloc block */ |
487 | bf->bitArray = GNUNET_malloc_large (size); | 485 | bf->bitArray = GNUNET_malloc_large (size); |
488 | if (bf->bitArray == NULL) | 486 | if (bf->bitArray == NULL) |
489 | { | 487 | { |
490 | if (bf->fh != NULL) | 488 | if (bf->fh != NULL) |
491 | GNUNET_DISK_file_close (bf->fh); | 489 | GNUNET_DISK_file_close (bf->fh); |
492 | GNUNET_free (bf->filename); | 490 | GNUNET_free (bf->filename); |
493 | GNUNET_free (bf); | 491 | GNUNET_free (bf); |
494 | return NULL; | 492 | return NULL; |
495 | } | 493 | } |
496 | bf->bitArraySize = size; | 494 | bf->bitArraySize = size; |
497 | bf->addressesPerElement = k; | 495 | bf->addressesPerElement = k; |
498 | memset (bf->bitArray, 0, bf->bitArraySize); | 496 | memset (bf->bitArray, 0, bf->bitArraySize); |
@@ -501,27 +499,27 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
501 | rbuff = GNUNET_malloc (BUFFSIZE); | 499 | rbuff = GNUNET_malloc (BUFFSIZE); |
502 | pos = 0; | 500 | pos = 0; |
503 | while (pos < size * 8) | 501 | while (pos < size * 8) |
502 | { | ||
503 | int res; | ||
504 | |||
505 | res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); | ||
506 | if (res == -1) | ||
507 | { | ||
508 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename); | ||
509 | } | ||
510 | if (res == 0) | ||
511 | break; /* is ok! we just did not use that many bits yet */ | ||
512 | for (i = 0; i < res; i++) | ||
504 | { | 513 | { |
505 | int res; | 514 | if ((rbuff[i] & 0x0F) != 0) |
506 | 515 | setBit (bf->bitArray, pos + i * 2); | |
507 | res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); | 516 | if ((rbuff[i] & 0xF0) != 0) |
508 | if (res == -1) | 517 | setBit (bf->bitArray, pos + i * 2 + 1); |
509 | { | ||
510 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename); | ||
511 | } | ||
512 | if (res == 0) | ||
513 | break; /* is ok! we just did not use that many bits yet */ | ||
514 | for (i = 0; i < res; i++) | ||
515 | { | ||
516 | if ((rbuff[i] & 0x0F) != 0) | ||
517 | setBit (bf->bitArray, pos + i * 2); | ||
518 | if ((rbuff[i] & 0xF0) != 0) | ||
519 | setBit (bf->bitArray, pos + i * 2 + 1); | ||
520 | } | ||
521 | if (res < BUFFSIZE) | ||
522 | break; | ||
523 | pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */ | ||
524 | } | 518 | } |
519 | if (res < BUFFSIZE) | ||
520 | break; | ||
521 | pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */ | ||
522 | } | ||
525 | GNUNET_free (rbuff); | 523 | GNUNET_free (rbuff); |
526 | return bf; | 524 | return bf; |
527 | } | 525 | } |
@@ -542,7 +540,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
542 | */ | 540 | */ |
543 | struct GNUNET_CONTAINER_BloomFilter * | 541 | struct GNUNET_CONTAINER_BloomFilter * |
544 | GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, | 542 | GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, |
545 | unsigned int k) | 543 | unsigned int k) |
546 | { | 544 | { |
547 | struct GNUNET_CONTAINER_BloomFilter *bf; | 545 | struct GNUNET_CONTAINER_BloomFilter *bf; |
548 | size_t ui; | 546 | size_t ui; |
@@ -553,19 +551,19 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, | |||
553 | while (ui < size) | 551 | while (ui < size) |
554 | ui *= 2; | 552 | ui *= 2; |
555 | if (size != ui) | 553 | if (size != ui) |
556 | { | 554 | { |
557 | GNUNET_break (0); | 555 | GNUNET_break (0); |
558 | return NULL; | 556 | return NULL; |
559 | } | 557 | } |
560 | bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); | 558 | bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter)); |
561 | bf->filename = NULL; | 559 | bf->filename = NULL; |
562 | bf->fh = NULL; | 560 | bf->fh = NULL; |
563 | bf->bitArray = GNUNET_malloc_large (size); | 561 | bf->bitArray = GNUNET_malloc_large (size); |
564 | if (bf->bitArray == NULL) | 562 | if (bf->bitArray == NULL) |
565 | { | 563 | { |
566 | GNUNET_free (bf); | 564 | GNUNET_free (bf); |
567 | return NULL; | 565 | return NULL; |
568 | } | 566 | } |
569 | bf->bitArraySize = size; | 567 | bf->bitArraySize = size; |
570 | bf->addressesPerElement = k; | 568 | bf->addressesPerElement = k; |
571 | if (data != NULL) | 569 | if (data != NULL) |
@@ -587,8 +585,8 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, | |||
587 | */ | 585 | */ |
588 | int | 586 | int |
589 | GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct | 587 | GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct |
590 | GNUNET_CONTAINER_BloomFilter *bf, | 588 | GNUNET_CONTAINER_BloomFilter *bf, |
591 | char *data, size_t size) | 589 | char *data, size_t size) |
592 | { | 590 | { |
593 | if (NULL == bf) | 591 | if (NULL == bf) |
594 | return GNUNET_SYSERR; | 592 | return GNUNET_SYSERR; |
@@ -645,7 +643,7 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf) | |||
645 | */ | 643 | */ |
646 | int | 644 | int |
647 | GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter | 645 | GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter |
648 | *bf, const GNUNET_HashCode * e) | 646 | *bf, const GNUNET_HashCode * e) |
649 | { | 647 | { |
650 | int res; | 648 | int res; |
651 | 649 | ||
@@ -665,7 +663,7 @@ GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter | |||
665 | */ | 663 | */ |
666 | void | 664 | void |
667 | GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, | 665 | GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, |
668 | const GNUNET_HashCode * e) | 666 | const GNUNET_HashCode * e) |
669 | { | 667 | { |
670 | if (NULL == bf) | 668 | if (NULL == bf) |
671 | return; | 669 | return; |
@@ -685,7 +683,7 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
685 | */ | 683 | */ |
686 | int | 684 | int |
687 | GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, | 685 | GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, |
688 | const char *data, size_t size) | 686 | const char *data, size_t size) |
689 | { | 687 | { |
690 | unsigned int i; | 688 | unsigned int i; |
691 | unsigned int n; | 689 | unsigned int n; |
@@ -719,8 +717,8 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
719 | */ | 717 | */ |
720 | int | 718 | int |
721 | GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, | 719 | GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, |
722 | const struct GNUNET_CONTAINER_BloomFilter | 720 | const struct GNUNET_CONTAINER_BloomFilter |
723 | *to_or, size_t size) | 721 | *to_or, size_t size) |
724 | { | 722 | { |
725 | unsigned int i; | 723 | unsigned int i; |
726 | unsigned int n; | 724 | unsigned int n; |
@@ -750,7 +748,7 @@ GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
750 | */ | 748 | */ |
751 | void | 749 | void |
752 | GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, | 750 | GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, |
753 | const GNUNET_HashCode * e) | 751 | const GNUNET_HashCode * e) |
754 | { | 752 | { |
755 | if (NULL == bf) | 753 | if (NULL == bf) |
756 | return; | 754 | return; |
@@ -772,9 +770,9 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
772 | */ | 770 | */ |
773 | void | 771 | void |
774 | GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, | 772 | GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, |
775 | GNUNET_HashCodeIterator iterator, | 773 | GNUNET_HashCodeIterator iterator, |
776 | void *iterator_cls, size_t size, | 774 | void *iterator_cls, size_t size, |
777 | unsigned int k) | 775 | unsigned int k) |
778 | { | 776 | { |
779 | GNUNET_HashCode hc; | 777 | GNUNET_HashCode hc; |
780 | unsigned int i; | 778 | unsigned int i; |
@@ -783,7 +781,7 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
783 | i = 1; | 781 | i = 1; |
784 | while (i < size) | 782 | while (i < size) |
785 | i *= 2; | 783 | i *= 2; |
786 | size = i; /* make sure it's a power of 2 */ | 784 | size = i; /* make sure it's a power of 2 */ |
787 | 785 | ||
788 | bf->bitArraySize = size; | 786 | bf->bitArraySize = size; |
789 | bf->bitArray = GNUNET_malloc (size); | 787 | bf->bitArray = GNUNET_malloc (size); |