GNUnet 0.27.0-9-g1409f30d5
 
Loading...
Searching...
No Matches
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.
 

Functions

struct GNUNET_CONTAINER_BloomFilterGNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, unsigned int k)
 Load a Bloom filter from a file.
 
struct GNUNET_CONTAINER_BloomFilterGNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, unsigned int k)
 Create a Bloom filter from raw bits.
 
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.
 
bool GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
 Test if an element is in the filter.
 
void GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
 Add an element to the filter.
 
void GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
 Remove an element from the filter.
 
struct GNUNET_CONTAINER_BloomFilterGNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter *bf)
 Create a copy of a bloomfilter.
 
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).
 
size_t GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter *bf)
 Get size of the bloom filter.
 
void GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf)
 Reset a Bloom filter to empty.
 
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.
 
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.
 
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.
 

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 !=
555 make_empty_file (bf->fh,
556 size * 4LL))
557 {
559 "write");
561 GNUNET_free (bf);
562 return NULL;
563 }
564 }
566 /* Alloc block */
568 if (NULL == bf->bitArray)
569 {
570 if (NULL != bf->fh)
572 GNUNET_free (bf->filename);
573 GNUNET_free (bf);
574 return NULL;
575 }
576 bf->bitArraySize = size;
577 bf->addressesPerElement = k;
578 if (GNUNET_YES != must_read)
579 return bf; /* already done! */
580 /* Read from the file what bits we can */
581 rbuff = GNUNET_malloc (BUFFSIZE);
582 pos = 0;
583 while (pos < ((off_t) size) * 8LL)
584 {
585 int res;
586
587 res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
588 if (res == -1)
589 {
591 GNUNET_free (rbuff);
592 GNUNET_free (bf->filename);
594 GNUNET_free (bf);
595 return NULL;
596 }
597 if (res == 0)
598 break; /* is ok! we just did not use that many bits yet */
599 for (i = 0; i < res; i++)
600 {
601 if ((rbuff[i] & 0x0F) != 0)
602 setBit (bf->bitArray, pos + i * 2);
603 if ((rbuff[i] & 0xF0) != 0)
604 setBit (bf->bitArray, pos + i * 2 + 1);
605 }
606 if (res < BUFFSIZE)
607 break;
608 pos += BUFFSIZE * 2; /* 2 bits per byte in the buffer */
609 }
610 GNUNET_free (rbuff);
611 return bf;
612}
#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:1308
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:557
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition disk.c:1386
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:704
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:206
@ 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:179
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 616 of file container_bloomfilter.c.

619{
621
622 if ((0 == k) || (0 == size))
623 return NULL;
625 bf->filename = NULL;
626 bf->fh = NULL;
628 if (NULL == bf->bitArray)
629 {
630 GNUNET_free (bf);
631 return NULL;
632 }
633 bf->bitArraySize = size;
634 bf->addressesPerElement = k;
635 if (NULL != data)
637 return bf;
638}
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(), handle_intersection_p2p_bf(), run(), run(), send_bloomfilter(), 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 642 of file container_bloomfilter.c.

646{
647 if (NULL == bf)
648 return GNUNET_SYSERR;
649 if (bf->bitArraySize != size)
650 return GNUNET_SYSERR;
652 return GNUNET_OK;
653}
@ 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_helper_make_put_message(), GDS_NEIGHBOURS_handle_get(), send_bloomfilter(), 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 685 of file container_bloomfilter.c.

688{
689 bool res;
690
691 if (NULL == bf)
692 return true;
693 res = true;
694 iterateBits (bf,
696 &res,
697 e);
698 return res;
699}
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(), filtered_map_initialization(), find_advertisable_hello(), GDS_am_closest_peer(), GDS_helper_make_put_message(), 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(), 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 703 of file container_bloomfilter.c.

705{
706 if (NULL == bf)
707 return;
708 iterateBits (bf,
710 bf,
711 e);
712}
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(), GNUNET_BLOCK_GROUP_bf_test_and_set(), GNUNET_CONTAINER_bloomfilter_resize(), GNUNET_DATACACHE_put(), iterator_bf_create(), iterator_bf_create(), print_put_message(), 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 773 of file container_bloomfilter.c.

775{
776 if (NULL == bf)
777 return;
778 if (NULL == bf->filename)
779 return;
780 iterateBits (bf,
782 bf,
783 e);
784}
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 657 of file container_bloomfilter.c.

658{
659 if (NULL == bf)
660 return;
661 if (bf->fh != NULL)
663 GNUNET_free (bf->filename);
664 GNUNET_free (bf->bitArray);
665 GNUNET_free (bf);
666}

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(), cb_handle_dht_p2p_get_local_result(), cleaning_task(), consider_for_advertising(), find_advertisable_hello(), free_peer(), GNUNET_DATACACHE_destroy(), handle_dht_local_put(), handle_dht_p2p_put(), intersection_op_cancel(), process_bf(), process_bf(), process_peer(), process_stat_done(), send_bloomfilter(), 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 670 of file container_bloomfilter.c.

671{
672 if (NULL == bf)
673 return;
674 memset (bf->bitArray,
675 0,
676 bf->bitArraySize);
677 if (bf->filename != NULL)
679 make_empty_file (bf->fh,
680 bf->bitArraySize * 4LL));
681}
#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, GNUNET_CONTAINER_BloomFilter::fh, GNUNET_CONTAINER_BloomFilter::filename, GNUNET_break, GNUNET_OK, 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 716 of file container_bloomfilter.c.

719{
720 unsigned int i;
721 unsigned int n;
722 unsigned long long *fc;
723 const unsigned long long *dc;
724
725 if (NULL == bf)
726 return GNUNET_YES;
727 if (bf->bitArraySize != size)
728 return GNUNET_SYSERR;
729 fc = (unsigned long long *) bf->bitArray;
730 dc = (const unsigned long long *) data;
731 n = size / sizeof(unsigned long long);
732
733 for (i = 0; i < n; i++)
734 fc[i] |= dc[i];
735 for (i = n * sizeof(unsigned long long); i < size; i++)
736 bf->bitArray[i] |= data[i];
737 return GNUNET_OK;
738}
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 742 of file container_bloomfilter.c.

745{
746 unsigned int i;
747 unsigned int n;
748 unsigned long long *fc;
749 const unsigned long long *dc;
750 size_t size;
751
752 if (NULL == bf)
753 return GNUNET_OK;
754 if (bf->bitArraySize != to_or->bitArraySize)
755 {
756 GNUNET_break (0);
757 return GNUNET_SYSERR;
758 }
759 size = bf->bitArraySize;
760 fc = (unsigned long long *) bf->bitArray;
761 dc = (const unsigned long long *) to_or->bitArray;
762 n = size / sizeof(unsigned long long);
763
764 for (i = 0; i < n; i++)
765 fc[i] |= dc[i];
766 for (i = n * sizeof(unsigned long long); i < size; i++)
767 bf->bitArray[i] |= to_or->bitArray[i];
768 return GNUNET_OK;
769}

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 788 of file container_bloomfilter.c.

793{
794 struct GNUNET_HashCode hc;
795 unsigned int i;
796
797 GNUNET_free (bf->bitArray);
798 i = 1;
799 while (i < size)
800 i *= 2;
801 size = i; /* make sure it's a power of 2 */
802 bf->addressesPerElement = k;
803 bf->bitArraySize = size;
805 if (NULL != bf->filename)
807 make_empty_file (bf->fh,
808 bf->bitArraySize * 4LL));
809 while (GNUNET_YES == iterator (iterator_cls, &hc))
811}
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_break, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_YES, make_empty_file(), and size.

Here is the call graph for this function: