GNUnet 0.21.1
Bloom filter

Probabilistic set tests. More...

Collaboration diagram for Bloom filter:

Typedefs

typedef int(* GNUNET_CONTAINER_HashCodeIterator) (void *cls, struct GNUNET_HashCode *next)
 Iterator over struct GNUNET_HashCode. More...
 

Functions

struct GNUNET_CONTAINER_BloomFilterGNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, unsigned int k)
 Load a Bloom filter from a file. More...
 
struct GNUNET_CONTAINER_BloomFilterGNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, unsigned int k)
 Create a Bloom filter from raw bits. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct GNUNET_CONTAINER_BloomFilter *bf, char *data, size_t size)
 Copy the raw data of this Bloom filter into the given data array. More...
 
bool GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
 Test if an element is in the filter. More...
 
void GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
 Add an element to the filter. More...
 
void GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
 Remove an element from the filter. More...
 
struct GNUNET_CONTAINER_BloomFilterGNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter *bf)
 Create a copy of a bloomfilter. More...
 
void GNUNET_CONTAINER_bloomfilter_free (struct GNUNET_CONTAINER_BloomFilter *bf)
 Free the space associated with a filter in memory, flush to drive if needed (do not free the space on the drive). More...
 
size_t GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter *bf)
 Get size of the bloom filter. More...
 
void GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf)
 Reset a Bloom filter to empty. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, const char *data, size_t size)
 "or" the entries of the given raw data array with the data of the given Bloom filter. More...
 
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_CONTAINER_BloomFilter *to_or)
 "or" the entries of the given raw data array with the data of the given Bloom filter. More...
 
void GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, GNUNET_CONTAINER_HashCodeIterator iterator, void *iterator_cls, size_t size, unsigned int k)
 Resize a bloom filter. More...
 

Detailed Description

Probabilistic set tests.

Typedef Documentation

◆ GNUNET_CONTAINER_HashCodeIterator

typedef int(* GNUNET_CONTAINER_HashCodeIterator) (void *cls, struct GNUNET_HashCode *next)

Iterator over struct GNUNET_HashCode.

Parameters
clsclosure
nextset to the next hash code
Returns
GNUNET_YES if next was updated GNUNET_NO if there are no more entries

Definition at line 130 of file gnunet_container_lib.h.

Function Documentation

◆ GNUNET_CONTAINER_bloomfilter_load()

struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_load ( const char *  filename,
size_t  size,
unsigned int  k 
)

Load a Bloom filter from a file.

Parameters
filenamethe name of the file (or the prefix)
sizethe size of the bloom-filter (number of bytes of storage space to use); will be rounded up to next power of 2
kthe number of GNUNET_CRYPTO_hash-functions to apply per element (number of bits set per element in the set)
Returns
the bloomfilter

Definition at line 472 of file container_bloomfilter.c.

475{
477 char *rbuff;
478 off_t pos;
479 int i;
480 size_t ui;
481 off_t fsize;
482 int must_read;
483
484 GNUNET_assert (NULL != filename);
485 if ((k == 0) || (size == 0))
486 return NULL;
487 if (size < BUFFSIZE)
488 size = BUFFSIZE;
489 ui = 1;
490 while ((ui < size) && (ui * 2 > ui))
491 ui *= 2;
492 size = ui; /* make sure it's a power of 2 */
493
495 /* Try to open a bloomfilter file */
501 if (NULL != bf->fh)
502 {
503 /* file existed, try to read it! */
504 must_read = GNUNET_YES;
505 if (GNUNET_OK !=
507 &fsize))
508 {
510 GNUNET_free (bf);
511 return NULL;
512 }
513 if (0 == fsize)
514 {
515 /* found existing empty file, just overwrite */
516 if (GNUNET_OK !=
517 make_empty_file (bf->fh,
518 size * 4LL))
519 {
521 "write");
523 GNUNET_free (bf);
524 return NULL;
525 }
526 }
527 else if (fsize != ((off_t) size) * 4LL)
528 {
529 GNUNET_log (
531 _ (
532 "Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"),
533 (unsigned long long) (size * 4LL),
534 (unsigned long long) fsize);
536 GNUNET_free (bf);
537 return NULL;
538 }
539 }
540 else
541 {
542 /* file did not exist, don't read, just create */
543 must_read = GNUNET_NO;
549 if (NULL == bf->fh)
550 {
551 GNUNET_free (bf);
552 return NULL;
553 }
554 if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
555 {
558 GNUNET_free (bf);
559 return NULL;
560 }
561 }
563 /* Alloc block */
565 if (NULL == bf->bitArray)
566 {
567 if (NULL != bf->fh)
569 GNUNET_free (bf->filename);
570 GNUNET_free (bf);
571 return NULL;
572 }
573 bf->bitArraySize = size;
574 bf->addressesPerElement = k;
575 if (GNUNET_YES != must_read)
576 return bf; /* already done! */
577 /* Read from the file what bits we can */
578 rbuff = GNUNET_malloc (BUFFSIZE);
579 pos = 0;
580 while (pos < ((off_t) size) * 8LL)
581 {
582 int res;
583
584 res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
585 if (res == -1)
586 {
588 GNUNET_free (rbuff);
589 GNUNET_free (bf->filename);
591 GNUNET_free (bf);
592 return NULL;
593 }
594 if (res == 0)
595 break; /* is ok! we just did not use that many bits yet */
596 for (i = 0; i < res; i++)
597 {
598 if ((rbuff[i] & 0x0F) != 0)
599 setBit (bf->bitArray, pos + i * 2);
600 if ((rbuff[i] & 0xF0) != 0)
601 setBit (bf->bitArray, pos + i * 2 + 1);
602 }
603 if (res < BUFFSIZE)
604 break;
605 pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */
606 }
607 GNUNET_free (rbuff);
608 return bf;
609}
#define BUFFSIZE
static enum GNUNET_GenericReturnValue make_empty_file(const struct GNUNET_DISK_FileHandle *fh, size_t size)
Creates a file filled with zeroes.
#define LOG_STRERROR_FILE(kind, syscall, filename)
static void setBit(char *bitArray, unsigned int bitIdx)
Sets a bit active in the bitArray.
static char * filename
static char * res
Currently read line or NULL on EOF.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1237
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:622
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
Definition: disk.c:192
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_OPEN_READWRITE
Open the file for both reading and writing.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_malloc_large(size)
Wrapper around malloc.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
size_t bitArraySize
Size of bitArray in bytes.
unsigned int addressesPerElement
How many bits we set for each stored element.
struct GNUNET_DISK_FileHandle * fh
The bit counter file on disk.
char * bitArray
The actual bloomfilter bit array.
char * filename
Filename of the filter.

References _, GNUNET_CONTAINER_BloomFilter::addressesPerElement, GNUNET_CONTAINER_BloomFilter::bitArray, GNUNET_CONTAINER_BloomFilter::bitArraySize, BUFFSIZE, GNUNET_CONTAINER_BloomFilter::fh, filename, GNUNET_CONTAINER_BloomFilter::filename, GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_handle_size(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_test(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_log_strerror, GNUNET_malloc, GNUNET_malloc_large, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_YES, LOG_STRERROR_FILE, make_empty_file(), res, setBit(), and size.

Referenced by GNUNET_DATACACHE_create(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_bloomfilter_init()

struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init ( const char *  data,
size_t  size,
unsigned int  k 
)

Create a Bloom filter from raw bits.

Parameters
datathe raw bits in memory (maybe NULL, in which case all bits should be considered to be zero).
sizethe size of the bloom-filter (number of bytes of storage space to use); also size of data – unless data is NULL. Must be a power of 2.
kthe number of GNUNET_CRYPTO_hash-functions to apply per element (number of bits set per element in the set)
Returns
the bloomfilter

Definition at line 613 of file container_bloomfilter.c.

616{
618
619 if ((0 == k) || (0 == size))
620 return NULL;
622 bf->filename = NULL;
623 bf->fh = NULL;
625 if (NULL == bf->bitArray)
626 {
627 GNUNET_free (bf);
628 return NULL;
629 }
630 bf->bitArraySize = size;
631 bf->addressesPerElement = k;
632 if (NULL != data)
634 return bf;
635}
static char * data
The data to insert into the dht.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.

References GNUNET_CONTAINER_BloomFilter::addressesPerElement, GNUNET_CONTAINER_BloomFilter::bitArray, GNUNET_CONTAINER_BloomFilter::bitArraySize, data, GNUNET_CONTAINER_BloomFilter::fh, GNUNET_CONTAINER_BloomFilter::filename, GNUNET_free, GNUNET_malloc_large, GNUNET_memcpy, GNUNET_new, and size.

Referenced by GNUNET_BLOCK_GROUP_bf_create(), GNUNET_CONTAINER_bloomfilter_copy(), GNUNET_DATACACHE_create(), handle_dht_local_put(), handle_dht_p2p_get(), handle_dht_p2p_put(), handle_intersection_p2p_bf(), run(), send_bloomfilter(), send_find_peer_message(), setup_filter(), and transmit_request().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_bloomfilter_get_raw_data()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_bloomfilter_get_raw_data ( const struct GNUNET_CONTAINER_BloomFilter bf,
char *  data,
size_t  size 
)

Copy the raw data of this Bloom filter into the given data array.

Parameters
datawhere to write the data
sizethe size of the given data array
Returns
GNUNET_SYSERR if the data array of the wrong size

Definition at line 639 of file container_bloomfilter.c.

643{
644 if (NULL == bf)
645 return GNUNET_SYSERR;
646 if (bf->bitArraySize != size)
647 return GNUNET_SYSERR;
649 return GNUNET_OK;
650}
@ GNUNET_SYSERR

References GNUNET_CONTAINER_BloomFilter::bitArray, GNUNET_CONTAINER_BloomFilter::bitArraySize, data, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, and size.

Referenced by bf_group_serialize_cb(), GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_put(), and send_bloomfilter().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_bloomfilter_test()

bool GNUNET_CONTAINER_bloomfilter_test ( const struct GNUNET_CONTAINER_BloomFilter bf,
const struct GNUNET_HashCode e 
)

Test if an element is in the filter.

Parameters
ethe element
bfthe filter
Returns
true if the element is in the filter, false if not

Definition at line 679 of file container_bloomfilter.c.

682{
683 bool res;
684
685 if (NULL == bf)
686 return true;
687 res = true;
688 iterateBits (bf,
690 &res,
691 e);
692 return res;
693}
static enum GNUNET_GenericReturnValue testBitCallback(void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit)
Callback: test if all bits are set.
static void iterateBits(const struct GNUNET_CONTAINER_BloomFilter *bf, BitIterator callback, void *arg, const struct GNUNET_HashCode *key)
Call an iterator for each bit that the bloomfilter must test or set for this element.

References iterateBits(), res, and testBitCallback().

Referenced by filtered_map_initialization(), find_advertisable_hello(), GDS_am_closest_peer(), GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_put(), get_target_peers(), GNUNET_BLOCK_GROUP_bf_test_and_set(), GNUNET_DATACACHE_get(), handle_dht_p2p_get(), handle_dht_p2p_put(), handle_get_key(), handle_put(), iterator_bf_reduce(), and select_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_bloomfilter_add()

void GNUNET_CONTAINER_bloomfilter_add ( struct GNUNET_CONTAINER_BloomFilter bf,
const struct GNUNET_HashCode e 
)

Add an element to the filter.

Parameters
bfthe filter
ethe element

Definition at line 697 of file container_bloomfilter.c.

699{
700 if (NULL == bf)
701 return;
702 iterateBits (bf,
704 bf,
705 e);
706}
static enum GNUNET_GenericReturnValue incrementBitCallback(void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit)
Callback: increment bit.

References incrementBitCallback(), and iterateBits().

Referenced by add_key_to_bloomfilter(), bf_group_mark_seen_cb(), GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_put(), get_target_peers(), GNUNET_BLOCK_GROUP_bf_test_and_set(), GNUNET_CONTAINER_bloomfilter_resize(), GNUNET_DATACACHE_put(), iterator_bf_create(), put_continuation(), schedule_next_hello(), and setup_filter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_bloomfilter_remove()

void GNUNET_CONTAINER_bloomfilter_remove ( struct GNUNET_CONTAINER_BloomFilter bf,
const struct GNUNET_HashCode e 
)

Remove an element from the filter.

Parameters
bfthe filter
ethe element to remove

Definition at line 767 of file container_bloomfilter.c.

769{
770 if (NULL == bf)
771 return;
772 if (NULL == bf->filename)
773 return;
774 iterateBits (bf,
776 bf,
777 e);
778}
static enum GNUNET_GenericReturnValue decrementBitCallback(void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit)
Callback: decrement bit.

References decrementBitCallback(), GNUNET_CONTAINER_BloomFilter::filename, and iterateBits().

Referenced by env_delete_notify(), expired_processor(), quota_processor(), and remove_continuation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_bloomfilter_copy()

struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_copy ( const struct GNUNET_CONTAINER_BloomFilter bf)

Create a copy of a bloomfilter.

Parameters
bfthe filter
Returns
copy of bf

Definition at line 108 of file container_bloomfilter.c.

110{
112 bf->bitArraySize,
114}
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.

References GNUNET_CONTAINER_BloomFilter::addressesPerElement, GNUNET_CONTAINER_BloomFilter::bitArray, GNUNET_CONTAINER_BloomFilter::bitArraySize, and GNUNET_CONTAINER_bloomfilter_init().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_bloomfilter_free()

void GNUNET_CONTAINER_bloomfilter_free ( struct GNUNET_CONTAINER_BloomFilter bf)

Free the space associated with a filter in memory, flush to drive if needed (do not free the space on the drive).

Parameters
bfthe filter

Definition at line 654 of file container_bloomfilter.c.

655{
656 if (NULL == bf)
657 return;
658 if (bf->fh != NULL)
660 GNUNET_free (bf->filename);
661 GNUNET_free (bf->bitArray);
662 GNUNET_free (bf);
663}

References GNUNET_CONTAINER_BloomFilter::bitArray, GNUNET_CONTAINER_BloomFilter::fh, GNUNET_CONTAINER_BloomFilter::filename, GNUNET_DISK_file_close(), and GNUNET_free.

Referenced by _GSS_operation_destroy(), bf_group_destroy_cb(), cleaning_task(), consider_for_advertising(), find_advertisable_hello(), free_peer(), GNUNET_DATACACHE_destroy(), handle_dht_local_put(), handle_dht_p2p_get(), handle_dht_p2p_put(), intersection_op_cancel(), process_bf(), process_peer(), process_stat_done(), send_bloomfilter(), send_find_peer_message(), and transmit_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_bloomfilter_get_size()

size_t GNUNET_CONTAINER_bloomfilter_get_size ( const struct GNUNET_CONTAINER_BloomFilter bf)

Get size of the bloom filter.

Parameters
bfthe filter
Returns
number of bytes used for the data of the bloom filter

Definition at line 98 of file container_bloomfilter.c.

100{
101 if (bf == NULL)
102 return 0;
103 return bf->bitArraySize;
104}

References GNUNET_CONTAINER_BloomFilter::bitArraySize.

◆ GNUNET_CONTAINER_bloomfilter_clear()

void GNUNET_CONTAINER_bloomfilter_clear ( struct GNUNET_CONTAINER_BloomFilter bf)

Reset a Bloom filter to empty.

Parameters
bfthe filter

Definition at line 667 of file container_bloomfilter.c.

668{
669 if (NULL == bf)
670 return;
671
672 memset (bf->bitArray, 0, bf->bitArraySize);
673 if (bf->filename != NULL)
674 make_empty_file (bf->fh, bf->bitArraySize * 4LL);
675}

References GNUNET_CONTAINER_BloomFilter::bitArray, GNUNET_CONTAINER_BloomFilter::bitArraySize, GNUNET_CONTAINER_BloomFilter::fh, GNUNET_CONTAINER_BloomFilter::filename, and make_empty_file().

Here is the call graph for this function:

◆ GNUNET_CONTAINER_bloomfilter_or()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_bloomfilter_or ( struct GNUNET_CONTAINER_BloomFilter bf,
const char *  data,
size_t  size 
)

"or" the entries of the given raw data array with the data of the given Bloom filter.

Assumes that the size of the data array and the current filter match.

Parameters
bfthe filter
datadata to OR-in
sizesize of data
Returns
GNUNET_OK on success

Definition at line 710 of file container_bloomfilter.c.

713{
714 unsigned int i;
715 unsigned int n;
716 unsigned long long *fc;
717 const unsigned long long *dc;
718
719 if (NULL == bf)
720 return GNUNET_YES;
721 if (bf->bitArraySize != size)
722 return GNUNET_SYSERR;
723 fc = (unsigned long long *) bf->bitArray;
724 dc = (const unsigned long long *) data;
725 n = size / sizeof(unsigned long long);
726
727 for (i = 0; i < n; i++)
728 fc[i] |= dc[i];
729 for (i = n * sizeof(unsigned long long); i < size; i++)
730 bf->bitArray[i] |= data[i];
731 return GNUNET_OK;
732}
static struct GNUNET_FS_DownloadContext * dc

References GNUNET_CONTAINER_BloomFilter::bitArray, GNUNET_CONTAINER_BloomFilter::bitArraySize, data, dc, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, and size.

◆ GNUNET_CONTAINER_bloomfilter_or2()

enum GNUNET_GenericReturnValue GNUNET_CONTAINER_bloomfilter_or2 ( struct GNUNET_CONTAINER_BloomFilter bf,
const struct GNUNET_CONTAINER_BloomFilter to_or 
)

"or" the entries of the given raw data array with the data of the given Bloom filter.

Assumes that the size of the two filters matches.

Parameters
bfthe filter
to_orthe bloomfilter to or-in
Returns
GNUNET_OK on success

Definition at line 736 of file container_bloomfilter.c.

739{
740 unsigned int i;
741 unsigned int n;
742 unsigned long long *fc;
743 const unsigned long long *dc;
744 size_t size;
745
746 if (NULL == bf)
747 return GNUNET_OK;
748 if (bf->bitArraySize != to_or->bitArraySize)
749 {
750 GNUNET_break (0);
751 return GNUNET_SYSERR;
752 }
753 size = bf->bitArraySize;
754 fc = (unsigned long long *) bf->bitArray;
755 dc = (const unsigned long long *) to_or->bitArray;
756 n = size / sizeof(unsigned long long);
757
758 for (i = 0; i < n; i++)
759 fc[i] |= dc[i];
760 for (i = n * sizeof(unsigned long long); i < size; i++)
761 bf->bitArray[i] |= to_or->bitArray[i];
762 return GNUNET_OK;
763}
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References GNUNET_CONTAINER_BloomFilter::bitArray, GNUNET_CONTAINER_BloomFilter::bitArraySize, dc, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, and size.

Referenced by bf_group_merge_cb().

Here is the caller graph for this function:

◆ GNUNET_CONTAINER_bloomfilter_resize()

void GNUNET_CONTAINER_bloomfilter_resize ( struct GNUNET_CONTAINER_BloomFilter bf,
GNUNET_CONTAINER_HashCodeIterator  iterator,
void *  iterator_cls,
size_t  size,
unsigned int  k 
)

Resize a bloom filter.

Note that this operation is pretty costly. Essentially, the Bloom filter needs to be completely re-build.

Parameters
bfthe filter
iteratoran iterator over all elements stored in the BF
iterator_clsclosure for iterator
sizethe new size for the filter
kthe new number of GNUNET_CRYPTO_hash-function to apply per element

Definition at line 782 of file container_bloomfilter.c.

787{
788 struct GNUNET_HashCode hc;
789 unsigned int i;
790
791 GNUNET_free (bf->bitArray);
792 i = 1;
793 while (i < size)
794 i *= 2;
795 size = i; /* make sure it's a power of 2 */
796 bf->addressesPerElement = k;
797 bf->bitArraySize = size;
799 if (NULL != bf->filename)
800 make_empty_file (bf->fh, bf->bitArraySize * 4LL);
801 while (GNUNET_YES == iterator (iterator_cls, &hc))
803}
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
A 512-bit hashcode.

References GNUNET_CONTAINER_BloomFilter::addressesPerElement, GNUNET_CONTAINER_BloomFilter::bitArray, GNUNET_CONTAINER_BloomFilter::bitArraySize, GNUNET_CONTAINER_BloomFilter::fh, GNUNET_CONTAINER_BloomFilter::filename, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_free, GNUNET_malloc, GNUNET_YES, make_empty_file(), and size.

Here is the call graph for this function: