aboutsummaryrefslogtreecommitdiff
path: root/src/util/container_bloomfilter.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/container_bloomfilter.c')
-rw-r--r--src/util/container_bloomfilter.c205
1 files changed, 106 insertions, 99 deletions
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c
index a41c0cf8a..fe7d86421 100644
--- a/src/util/container_bloomfilter.c
+++ b/src/util/container_bloomfilter.c
@@ -42,11 +42,17 @@
42#include "platform.h" 42#include "platform.h"
43#include "gnunet_util_lib.h" 43#include "gnunet_util_lib.h"
44 44
45#define LOG(kind,...) GNUNET_log_from (kind, "util-container-bloomfilter", __VA_ARGS__) 45#define LOG(kind, ...) \
46 GNUNET_log_from (kind, "util-container-bloomfilter", __VA_ARGS__)
46 47
47#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-container-bloomfilter", syscall) 48#define LOG_strerror(kind, syscall) \
49 GNUNET_log_from_strerror (kind, "util-container-bloomfilter", syscall)
48 50
49#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-container-bloomfilter", syscall, filename) 51#define LOG_strerror_FILE(kind, syscall, filename) \
52 GNUNET_log_from_strerror_file (kind, \
53 "util-container-bloomfilter", \
54 syscall, \
55 filename)
50 56
51struct GNUNET_CONTAINER_BloomFilter 57struct GNUNET_CONTAINER_BloomFilter
52{ 58{
@@ -75,7 +81,6 @@ struct GNUNET_CONTAINER_BloomFilter
75 * Size of bitArray in bytes 81 * Size of bitArray in bytes
76 */ 82 */
77 size_t bitArraySize; 83 size_t bitArraySize;
78
79}; 84};
80 85
81 86
@@ -86,8 +91,8 @@ struct GNUNET_CONTAINER_BloomFilter
86 * @return addresses set per element in the bf 91 * @return addresses set per element in the bf
87 */ 92 */
88size_t 93size_t
89GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINER_BloomFilter 94GNUNET_CONTAINER_bloomfilter_get_element_addresses (
90 *bf) 95 const struct GNUNET_CONTAINER_BloomFilter *bf)
91{ 96{
92 if (bf == NULL) 97 if (bf == NULL)
93 return 0; 98 return 0;
@@ -102,8 +107,8 @@ GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINE
102 * @return number of bytes used for the data of the bloom filter 107 * @return number of bytes used for the data of the bloom filter
103 */ 108 */
104size_t 109size_t
105GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter 110GNUNET_CONTAINER_bloomfilter_get_size (
106 *bf) 111 const struct GNUNET_CONTAINER_BloomFilter *bf)
107{ 112{
108 if (bf == NULL) 113 if (bf == NULL)
109 return 0; 114 return 0;
@@ -118,10 +123,11 @@ GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter
118 * @return copy of the bf 123 * @return copy of the bf
119 */ 124 */
120struct GNUNET_CONTAINER_BloomFilter * 125struct GNUNET_CONTAINER_BloomFilter *
121GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter 126GNUNET_CONTAINER_bloomfilter_copy (
122 *bf) 127 const struct GNUNET_CONTAINER_BloomFilter *bf)
123{ 128{
124 return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray, bf->bitArraySize, 129 return GNUNET_CONTAINER_bloomfilter_init (bf->bitArray,
130 bf->bitArraySize,
125 bf->addressesPerElement); 131 bf->addressesPerElement);
126} 132}
127 133
@@ -193,7 +199,8 @@ testBit (char *bitArray, unsigned int bitIdx)
193 * @param fh A file to keep the 4 bit address usage counters in 199 * @param fh A file to keep the 4 bit address usage counters in
194 */ 200 */
195static void 201static void
196incrementBit (char *bitArray, unsigned int bitIdx, 202incrementBit (char *bitArray,
203 unsigned int bitIdx,
197 const struct GNUNET_DISK_FileHandle *fh) 204 const struct GNUNET_DISK_FileHandle *fh)
198{ 205{
199 off_t fileSlot; 206 off_t fileSlot;
@@ -241,7 +248,8 @@ incrementBit (char *bitArray, unsigned int bitIdx,
241 * @param fh A file to keep the 4bit address usage counters in 248 * @param fh A file to keep the 4bit address usage counters in
242 */ 249 */
243static void 250static void
244decrementBit (char *bitArray, unsigned int bitIdx, 251decrementBit (char *bitArray,
252 unsigned int bitIdx,
245 const struct GNUNET_DISK_FileHandle *fh) 253 const struct GNUNET_DISK_FileHandle *fh)
246{ 254{
247 off_t fileslot; 255 off_t fileslot;
@@ -251,15 +259,16 @@ decrementBit (char *bitArray, unsigned int bitIdx,
251 unsigned int targetLoc; 259 unsigned int targetLoc;
252 260
253 if (GNUNET_DISK_handle_invalid (fh)) 261 if (GNUNET_DISK_handle_invalid (fh))
254 return; /* cannot decrement! */ 262 return; /* cannot decrement! */
255 /* Each char slot in the counter file holds two 4 bit counters */ 263 /* Each char slot in the counter file holds two 4 bit counters */
256 fileslot = bitIdx / 2; 264 fileslot = bitIdx / 2;
257 targetLoc = bitIdx % 2; 265 targetLoc = bitIdx % 2;
258 if (GNUNET_SYSERR == GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET)) 266 if (GNUNET_SYSERR ==
259 { 267 GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
260 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek"); 268 {
261 return; 269 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
262 } 270 return;
271 }
263 if (1 != GNUNET_DISK_file_read (fh, &value, 1)) 272 if (1 != GNUNET_DISK_file_read (fh, &value, 1))
264 value = 0; 273 value = 0;
265 low = value & 0xF; 274 low = value & 0xF;
@@ -285,11 +294,12 @@ decrementBit (char *bitArray, unsigned int bitIdx,
285 } 294 }
286 } 295 }
287 value = ((high << 4) | low); 296 value = ((high << 4) | low);
288 if (GNUNET_SYSERR == GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET)) 297 if (GNUNET_SYSERR ==
289 { 298 GNUNET_DISK_file_seek (fh, fileslot, GNUNET_DISK_SEEK_SET))
290 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek"); 299 {
291 return; 300 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "seek");
292 } 301 return;
302 }
293 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); 303 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1));
294} 304}
295 305
@@ -319,13 +329,13 @@ make_empty_file (const struct GNUNET_DISK_FileHandle *fh, size_t size)
319 { 329 {
320 res = GNUNET_DISK_file_write (fh, buffer, sizeof (buffer)); 330 res = GNUNET_DISK_file_write (fh, buffer, sizeof (buffer));
321 if (res >= 0) 331 if (res >= 0)
322 bytesleft -= res; 332 bytesleft -= res;
323 } 333 }
324 else 334 else
325 { 335 {
326 res = GNUNET_DISK_file_write (fh, buffer, bytesleft); 336 res = GNUNET_DISK_file_write (fh, buffer, bytesleft);
327 if (res >= 0) 337 if (res >= 0)
328 bytesleft -= res; 338 bytesleft -= res;
329 } 339 }
330 if (GNUNET_SYSERR == res) 340 if (GNUNET_SYSERR == res)
331 return GNUNET_SYSERR; 341 return GNUNET_SYSERR;
@@ -346,7 +356,7 @@ make_empty_file (const struct GNUNET_DISK_FileHandle *fh, size_t size)
346 * @return GNUNET_YES to continue, GNUNET_NO to stop early 356 * @return GNUNET_YES to continue, GNUNET_NO to stop early
347 */ 357 */
348typedef int (*BitIterator) (void *cls, 358typedef int (*BitIterator) (void *cls,
349 const struct GNUNET_CONTAINER_BloomFilter * bf, 359 const struct GNUNET_CONTAINER_BloomFilter *bf,
350 unsigned int bit); 360 unsigned int bit);
351 361
352 362
@@ -361,7 +371,9 @@ typedef int (*BitIterator) (void *cls,
361 */ 371 */
362static void 372static void
363iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf, 373iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
364 BitIterator callback, void *arg, const struct GNUNET_HashCode *key) 374 BitIterator callback,
375 void *arg,
376 const struct GNUNET_HashCode *key)
365{ 377{
366 struct GNUNET_HashCode tmp[2]; 378 struct GNUNET_HashCode tmp[2];
367 int bitCount; 379 int bitCount;
@@ -378,9 +390,10 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
378 while (slot < (sizeof (struct GNUNET_HashCode) / sizeof (uint32_t))) 390 while (slot < (sizeof (struct GNUNET_HashCode) / sizeof (uint32_t)))
379 { 391 {
380 if (GNUNET_YES != 392 if (GNUNET_YES !=
381 callback (arg, bf, 393 callback (arg,
382 ntohl ((((uint32_t *) & tmp[round & 1])[slot])) % 394 bf,
383 ((bf->bitArraySize * 8LL)))) 395 ntohl ((((uint32_t *) &tmp[round & 1])[slot])) %
396 ((bf->bitArraySize * 8LL))))
384 return; 397 return;
385 slot++; 398 slot++;
386 bitCount--; 399 bitCount--;
@@ -389,7 +402,8 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
389 } 402 }
390 if (bitCount > 0) 403 if (bitCount > 0)
391 { 404 {
392 GNUNET_CRYPTO_hash (&tmp[round & 1], sizeof (struct GNUNET_HashCode), 405 GNUNET_CRYPTO_hash (&tmp[round & 1],
406 sizeof (struct GNUNET_HashCode),
393 &tmp[(round + 1) & 1]); 407 &tmp[(round + 1) & 1]);
394 round++; 408 round++;
395 slot = 0; 409 slot = 0;
@@ -407,7 +421,8 @@ iterateBits (const struct GNUNET_CONTAINER_BloomFilter *bf,
407 * @return GNUNET_YES 421 * @return GNUNET_YES
408 */ 422 */
409static int 423static int
410incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, 424incrementBitCallback (void *cls,
425 const struct GNUNET_CONTAINER_BloomFilter *bf,
411 unsigned int bit) 426 unsigned int bit)
412{ 427{
413 struct GNUNET_CONTAINER_BloomFilter *b = cls; 428 struct GNUNET_CONTAINER_BloomFilter *b = cls;
@@ -426,7 +441,8 @@ incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
426 * @return GNUNET_YES 441 * @return GNUNET_YES
427 */ 442 */
428static int 443static int
429decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, 444decrementBitCallback (void *cls,
445 const struct GNUNET_CONTAINER_BloomFilter *bf,
430 unsigned int bit) 446 unsigned int bit)
431{ 447{
432 struct GNUNET_CONTAINER_BloomFilter *b = cls; 448 struct GNUNET_CONTAINER_BloomFilter *b = cls;
@@ -445,7 +461,8 @@ decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
445 * @return YES if the bit is set, NO if not 461 * @return YES if the bit is set, NO if not
446 */ 462 */
447static int 463static int
448testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, 464testBitCallback (void *cls,
465 const struct GNUNET_CONTAINER_BloomFilter *bf,
449 unsigned int bit) 466 unsigned int bit)
450{ 467{
451 int *arg = cls; 468 int *arg = cls;
@@ -472,7 +489,8 @@ testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf,
472 * @return the bloomfilter 489 * @return the bloomfilter
473 */ 490 */
474struct GNUNET_CONTAINER_BloomFilter * 491struct GNUNET_CONTAINER_BloomFilter *
475GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, 492GNUNET_CONTAINER_bloomfilter_load (const char *filename,
493 size_t size,
476 unsigned int k) 494 unsigned int k)
477{ 495{
478 struct GNUNET_CONTAINER_BloomFilter *bf; 496 struct GNUNET_CONTAINER_BloomFilter *bf;
@@ -489,25 +507,22 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
489 if (size < BUFFSIZE) 507 if (size < BUFFSIZE)
490 size = BUFFSIZE; 508 size = BUFFSIZE;
491 ui = 1; 509 ui = 1;
492 while ( (ui < size) && 510 while ((ui < size) && (ui * 2 > ui))
493 (ui * 2 > ui) )
494 ui *= 2; 511 ui *= 2;
495 size = ui; /* make sure it's a power of 2 */ 512 size = ui; /* make sure it's a power of 2 */
496 513
497 bf = GNUNET_new (struct GNUNET_CONTAINER_BloomFilter); 514 bf = GNUNET_new (struct GNUNET_CONTAINER_BloomFilter);
498 /* Try to open a bloomfilter file */ 515 /* Try to open a bloomfilter file */
499 if (GNUNET_YES == GNUNET_DISK_file_test (filename)) 516 if (GNUNET_YES == GNUNET_DISK_file_test (filename))
500 bf->fh = 517 bf->fh = GNUNET_DISK_file_open (filename,
501 GNUNET_DISK_file_open (filename, 518 GNUNET_DISK_OPEN_READWRITE,
502 GNUNET_DISK_OPEN_READWRITE, 519 GNUNET_DISK_PERM_USER_READ |
503 GNUNET_DISK_PERM_USER_READ | 520 GNUNET_DISK_PERM_USER_WRITE);
504 GNUNET_DISK_PERM_USER_WRITE);
505 if (NULL != bf->fh) 521 if (NULL != bf->fh)
506 { 522 {
507 /* file existed, try to read it! */ 523 /* file existed, try to read it! */
508 must_read = GNUNET_YES; 524 must_read = GNUNET_YES;
509 if (GNUNET_OK != 525 if (GNUNET_OK != GNUNET_DISK_file_handle_size (bf->fh, &fsize))
510 GNUNET_DISK_file_handle_size (bf->fh, &fsize))
511 { 526 {
512 GNUNET_DISK_file_close (bf->fh); 527 GNUNET_DISK_file_close (bf->fh);
513 GNUNET_free (bf); 528 GNUNET_free (bf);
@@ -516,22 +531,22 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
516 if (0 == fsize) 531 if (0 == fsize)
517 { 532 {
518 /* found existing empty file, just overwrite */ 533 /* found existing empty file, just overwrite */
519 if (GNUNET_OK != 534 if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
520 make_empty_file (bf->fh, size * 4LL))
521 { 535 {
522 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 536 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
523 "write"); 537 GNUNET_DISK_file_close (bf->fh);
524 GNUNET_DISK_file_close (bf->fh); 538 GNUNET_free (bf);
525 GNUNET_free (bf); 539 return NULL;
526 return NULL;
527 } 540 }
528 } 541 }
529 else if (fsize != ((off_t) size) * 4LL) 542 else if (fsize != ((off_t) size) * 4LL)
530 { 543 {
531 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 544 GNUNET_log (
532 _("Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"), 545 GNUNET_ERROR_TYPE_ERROR,
533 (unsigned long long) (size * 4LL), 546 _ (
534 (unsigned long long) fsize); 547 "Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"),
548 (unsigned long long) (size * 4LL),
549 (unsigned long long) fsize);
535 GNUNET_DISK_file_close (bf->fh); 550 GNUNET_DISK_file_close (bf->fh);
536 GNUNET_free (bf); 551 GNUNET_free (bf);
537 return NULL; 552 return NULL;
@@ -541,21 +556,19 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
541 { 556 {
542 /* file did not exist, don't read, just create */ 557 /* file did not exist, don't read, just create */
543 must_read = GNUNET_NO; 558 must_read = GNUNET_NO;
544 bf->fh = 559 bf->fh = GNUNET_DISK_file_open (filename,
545 GNUNET_DISK_file_open (filename, 560 GNUNET_DISK_OPEN_CREATE |
546 GNUNET_DISK_OPEN_CREATE | 561 GNUNET_DISK_OPEN_READWRITE,
547 GNUNET_DISK_OPEN_READWRITE, 562 GNUNET_DISK_PERM_USER_READ |
548 GNUNET_DISK_PERM_USER_READ | 563 GNUNET_DISK_PERM_USER_WRITE);
549 GNUNET_DISK_PERM_USER_WRITE);
550 if (NULL == bf->fh) 564 if (NULL == bf->fh)
551 { 565 {
552 GNUNET_free (bf); 566 GNUNET_free (bf);
553 return NULL; 567 return NULL;
554 } 568 }
555 if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL)) 569 if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
556 { 570 {
557 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 571 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
558 "write");
559 GNUNET_DISK_file_close (bf->fh); 572 GNUNET_DISK_file_close (bf->fh);
560 GNUNET_free (bf); 573 GNUNET_free (bf);
561 return NULL; 574 return NULL;
@@ -583,14 +596,10 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
583 { 596 {
584 int res; 597 int res;
585 598
586 res = GNUNET_DISK_file_read (bf->fh, 599 res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
587 rbuff,
588 BUFFSIZE);
589 if (res == -1) 600 if (res == -1)
590 { 601 {
591 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 602 LOG_strerror_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename);
592 "read",
593 bf->filename);
594 GNUNET_free (rbuff); 603 GNUNET_free (rbuff);
595 GNUNET_free (bf->filename); 604 GNUNET_free (bf->filename);
596 GNUNET_DISK_file_close (bf->fh); 605 GNUNET_DISK_file_close (bf->fh);
@@ -598,7 +607,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
598 return NULL; 607 return NULL;
599 } 608 }
600 if (res == 0) 609 if (res == 0)
601 break; /* is ok! we just did not use that many bits yet */ 610 break; /* is ok! we just did not use that many bits yet */
602 for (i = 0; i < res; i++) 611 for (i = 0; i < res; i++)
603 { 612 {
604 if ((rbuff[i] & 0x0F) != 0) 613 if ((rbuff[i] & 0x0F) != 0)
@@ -608,7 +617,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
608 } 617 }
609 if (res < BUFFSIZE) 618 if (res < BUFFSIZE)
610 break; 619 break;
611 pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */ 620 pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */
612 } 621 }
613 GNUNET_free (rbuff); 622 GNUNET_free (rbuff);
614 return bf; 623 return bf;
@@ -629,7 +638,8 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
629 * @return the bloomfilter 638 * @return the bloomfilter
630 */ 639 */
631struct GNUNET_CONTAINER_BloomFilter * 640struct GNUNET_CONTAINER_BloomFilter *
632GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, 641GNUNET_CONTAINER_bloomfilter_init (const char *data,
642 size_t size,
633 unsigned int k) 643 unsigned int k)
634{ 644{
635 struct GNUNET_CONTAINER_BloomFilter *bf; 645 struct GNUNET_CONTAINER_BloomFilter *bf;
@@ -663,9 +673,10 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size,
663 * @return #GNUNET_SYSERR if the data array is not big enough 673 * @return #GNUNET_SYSERR if the data array is not big enough
664 */ 674 */
665int 675int
666GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct 676GNUNET_CONTAINER_bloomfilter_get_raw_data (
667 GNUNET_CONTAINER_BloomFilter *bf, 677 const struct GNUNET_CONTAINER_BloomFilter *bf,
668 char *data, size_t size) 678 char *data,
679 size_t size)
669{ 680{
670 if (NULL == bf) 681 if (NULL == bf)
671 return GNUNET_SYSERR; 682 return GNUNET_SYSERR;
@@ -721,8 +732,9 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf)
721 * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not 732 * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not
722 */ 733 */
723int 734int
724GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf, 735GNUNET_CONTAINER_bloomfilter_test (
725 const struct GNUNET_HashCode * e) 736 const struct GNUNET_CONTAINER_BloomFilter *bf,
737 const struct GNUNET_HashCode *e)
726{ 738{
727 int res; 739 int res;
728 740
@@ -742,7 +754,7 @@ GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf
742 */ 754 */
743void 755void
744GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, 756GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
745 const struct GNUNET_HashCode * e) 757 const struct GNUNET_HashCode *e)
746{ 758{
747 if (NULL == bf) 759 if (NULL == bf)
748 return; 760 return;
@@ -763,7 +775,7 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
763int 775int
764GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, 776GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
765 const char *data, 777 const char *data,
766 size_t size) 778 size_t size)
767{ 779{
768 unsigned int i; 780 unsigned int i;
769 unsigned int n; 781 unsigned int n;
@@ -796,8 +808,9 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
796 * @return #GNUNET_OK on success 808 * @return #GNUNET_OK on success
797 */ 809 */
798int 810int
799GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, 811GNUNET_CONTAINER_bloomfilter_or2 (
800 const struct GNUNET_CONTAINER_BloomFilter *to_or) 812 struct GNUNET_CONTAINER_BloomFilter *bf,
813 const struct GNUNET_CONTAINER_BloomFilter *to_or)
801{ 814{
802 unsigned int i; 815 unsigned int i;
803 unsigned int n; 816 unsigned int n;
@@ -839,10 +852,7 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
839 return; 852 return;
840 if (NULL == bf->filename) 853 if (NULL == bf->filename)
841 return; 854 return;
842 iterateBits (bf, 855 iterateBits (bf, &decrementBitCallback, bf, e);
843 &decrementBitCallback,
844 bf,
845 e);
846} 856}
847 857
848/** 858/**
@@ -860,7 +870,7 @@ void
860GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, 870GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
861 GNUNET_CONTAINER_HashCodeIterator iterator, 871 GNUNET_CONTAINER_HashCodeIterator iterator,
862 void *iterator_cls, 872 void *iterator_cls,
863 size_t size, 873 size_t size,
864 unsigned int k) 874 unsigned int k)
865{ 875{
866 struct GNUNET_HashCode hc; 876 struct GNUNET_HashCode hc;
@@ -870,17 +880,14 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
870 i = 1; 880 i = 1;
871 while (i < size) 881 while (i < size)
872 i *= 2; 882 i *= 2;
873 size = i; /* make sure it's a power of 2 */ 883 size = i; /* make sure it's a power of 2 */
874 bf->addressesPerElement = k; 884 bf->addressesPerElement = k;
875 bf->bitArraySize = size; 885 bf->bitArraySize = size;
876 bf->bitArray = GNUNET_malloc (size); 886 bf->bitArray = GNUNET_malloc (size);
877 if (NULL != bf->filename) 887 if (NULL != bf->filename)
878 make_empty_file (bf->fh, 888 make_empty_file (bf->fh, bf->bitArraySize * 4LL);
879 bf->bitArraySize * 4LL); 889 while (GNUNET_YES == iterator (iterator_cls, &hc))
880 while (GNUNET_YES == iterator (iterator_cls, 890 GNUNET_CONTAINER_bloomfilter_add (bf, &hc);
881 &hc))
882 GNUNET_CONTAINER_bloomfilter_add (bf,
883 &hc);
884} 891}
885 892
886/* end of container_bloomfilter.c */ 893/* end of container_bloomfilter.c */