data structure used to reduce disk accesses. More...
Go to the source code of this file.
Data Structures | |
struct | GNUNET_CONTAINER_BloomFilter |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "util-container-bloomfilter", __VA_ARGS__) |
#define | LOG_STRERROR(kind, syscall) GNUNET_log_from_strerror (kind, "util-container-bloomfilter", syscall) |
#define | LOG_STRERROR_FILE(kind, syscall, filename) |
#define | BUFFSIZE 65536 |
Typedefs | |
typedef enum GNUNET_GenericReturnValue(* | BitIterator) (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) |
Iterator (callback) method to be called by the bloomfilter iterator on each bit that is to be set or tested for the key. More... | |
Functions | |
size_t | GNUNET_CONTAINER_bloomfilter_get_element_addresses (const struct GNUNET_CONTAINER_BloomFilter *bf) |
Get the number of the addresses set per element in the bloom filter. More... | |
size_t | GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter *bf) |
Get size of the bloom filter. More... | |
struct GNUNET_CONTAINER_BloomFilter * | GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter *bf) |
Create a copy of a bloomfilter. More... | |
static void | setBit (char *bitArray, unsigned int bitIdx) |
Sets a bit active in the bitArray. More... | |
static void | clearBit (char *bitArray, unsigned int bitIdx) |
Clears a bit from bitArray. More... | |
static bool | testBit (char *bitArray, unsigned int bitIdx) |
Checks if a bit is active in the bitArray. More... | |
static void | incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh) |
Sets a bit active in the bitArray and increments bit-specific usage counter on disk (but only if the counter was below 4 bit max (==15)). More... | |
static void | decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh) |
Clears a bit from bitArray if the respective usage counter on the disk hits/is zero. More... | |
static enum GNUNET_GenericReturnValue | make_empty_file (const struct GNUNET_DISK_FileHandle *fh, size_t size) |
Creates a file filled with zeroes. More... | |
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. More... | |
static enum GNUNET_GenericReturnValue | incrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) |
Callback: increment bit. More... | |
static enum GNUNET_GenericReturnValue | decrementBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) |
Callback: decrement bit. More... | |
static enum GNUNET_GenericReturnValue | testBitCallback (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) |
Callback: test if all bits are set. More... | |
struct GNUNET_CONTAINER_BloomFilter * | GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, unsigned int k) |
Load a Bloom filter from a file. More... | |
struct GNUNET_CONTAINER_BloomFilter * | GNUNET_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... | |
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... | |
void | GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf) |
Reset a Bloom filter to empty. 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... | |
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_remove (struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e) |
Remove an element from the 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... | |
data structure used to reduce disk accesses.
The idea basically: Create a signature for each element in the database. Add those signatures to a bit array. When doing a lookup, check if the bit array matches the signature of the requested element. If yes, address the disk, otherwise return 'not found'.
A property of the bloom filter is that sometimes we will have a match even if the element is not on the disk (then we do an unnecessary disk access), but what's most important is that we never get a single "false negative".
To be able to delete entries from the bloom filter, we maintain a 4 bit counter in the file on the drive (we still use only one bit in memory).
Definition in file container_bloomfilter.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "util-container-bloomfilter", __VA_ARGS__) |
Definition at line 46 of file container_bloomfilter.c.
#define LOG_STRERROR | ( | kind, | |
syscall | |||
) | GNUNET_log_from_strerror (kind, "util-container-bloomfilter", syscall) |
Definition at line 49 of file container_bloomfilter.c.
#define LOG_STRERROR_FILE | ( | kind, | |
syscall, | |||
filename | |||
) |
Definition at line 52 of file container_bloomfilter.c.
#define BUFFSIZE 65536 |
Definition at line 295 of file container_bloomfilter.c.
typedef enum GNUNET_GenericReturnValue(* BitIterator) (void *cls, const struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) |
Iterator (callback) method to be called by the bloomfilter iterator on each bit that is to be set or tested for the key.
cls | closure |
bf | the filter to manipulate |
bit | the current bit |
Definition at line 305 of file container_bloomfilter.c.
|
static |
Sets a bit active in the bitArray.
Increment bit-specific usage counter on disk only if below 4bit max (==15).
bitArray | memory area to set the bit in |
bitIdx | which bit to set |
Definition at line 125 of file container_bloomfilter.c.
References GNUNET_CONTAINER_BloomFilter::bitArray.
Referenced by GNUNET_CONTAINER_bloomfilter_load(), and incrementBit().
|
static |
Clears a bit from bitArray.
Bit is cleared from the array only if the respective usage counter on the disk hits/is zero.
bitArray | memory area to set the bit in |
bitIdx | which bit to unset |
Definition at line 145 of file container_bloomfilter.c.
References GNUNET_CONTAINER_BloomFilter::bitArray.
Referenced by decrementBit().
|
static |
Checks if a bit is active in the bitArray.
bitArray | memory area to set the bit in |
bitIdx | which bit to test |
Definition at line 164 of file container_bloomfilter.c.
References GNUNET_CONTAINER_BloomFilter::bitArray.
Referenced by testBitCallback().
|
static |
Sets a bit active in the bitArray and increments bit-specific usage counter on disk (but only if the counter was below 4 bit max (==15)).
bitArray | memory area to set the bit in |
bitIdx | which bit to test |
fh | A file to keep the 4 bit address usage counters in |
Definition at line 188 of file container_bloomfilter.c.
References GNUNET_CONTAINER_BloomFilter::bitArray, GNUNET_CONTAINER_BloomFilter::fh, GNUNET_assert, GNUNET_DISK_file_read(), GNUNET_DISK_file_seek(), GNUNET_DISK_file_write(), GNUNET_DISK_handle_invalid(), GNUNET_DISK_SEEK_SET, setBit(), and value.
Referenced by incrementBitCallback().
|
static |
Clears a bit from bitArray if the respective usage counter on the disk hits/is zero.
bitArray | memory area to set the bit in |
bitIdx | which bit to test |
fh | A file to keep the 4bit address usage counters in |
Definition at line 239 of file container_bloomfilter.c.
References GNUNET_CONTAINER_BloomFilter::bitArray, clearBit(), GNUNET_CONTAINER_BloomFilter::fh, GNUNET_assert, GNUNET_DISK_file_read(), GNUNET_DISK_file_seek(), GNUNET_DISK_file_write(), GNUNET_DISK_handle_invalid(), GNUNET_DISK_SEEK_SET, GNUNET_ERROR_TYPE_ERROR, GNUNET_log_strerror, GNUNET_SYSERR, and value.
Referenced by decrementBitCallback().
|
static |
Creates a file filled with zeroes.
fh | the file handle |
size | the size of the file |
Definition at line 305 of file container_bloomfilter.c.
Referenced by GNUNET_CONTAINER_bloomfilter_clear(), GNUNET_CONTAINER_bloomfilter_load(), and GNUNET_CONTAINER_bloomfilter_resize().
|
static |
Call an iterator for each bit that the bloomfilter must test or set for this element.
bf | the filter |
callback | the method to call |
arg | extra argument to callback |
key | the key for which we iterate over the BF bits |
Definition at line 365 of file container_bloomfilter.c.
References GNUNET_CONTAINER_BloomFilter::addressesPerElement, find_typedefs::arg, GNUNET_CONTAINER_BloomFilter::bitArraySize, GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_YES, and key.
Referenced by GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_remove(), and GNUNET_CONTAINER_bloomfilter_test().
|
static |
Callback: increment bit.
cls | pointer to writeable form of bf |
bf | the filter to manipulate |
bit | the bit to increment |
Definition at line 410 of file container_bloomfilter.c.
References GNUNET_CONTAINER_BloomFilter::bitArray, GNUNET_CONTAINER_BloomFilter::fh, GNUNET_YES, and incrementBit().
Referenced by GNUNET_CONTAINER_bloomfilter_add().
|
static |
Callback: decrement bit.
cls | pointer to writeable form of bf |
bf | the filter to manipulate |
bit | the bit to decrement |
Definition at line 432 of file container_bloomfilter.c.
References GNUNET_CONTAINER_BloomFilter::bitArray, decrementBit(), GNUNET_CONTAINER_BloomFilter::fh, and GNUNET_YES.
Referenced by GNUNET_CONTAINER_bloomfilter_remove().
|
static |
Callback: test if all bits are set.
cls | pointer set to false if bit is not set |
bf | the filter |
bit | the bit to test |
Definition at line 454 of file container_bloomfilter.c.
References find_typedefs::arg, GNUNET_CONTAINER_BloomFilter::bitArray, GNUNET_NO, GNUNET_YES, and testBit().
Referenced by GNUNET_CONTAINER_bloomfilter_test().