A space-efficent probabilistic set for membership test, false postives are possible, but false negatives are not. More...
#include <BloomFilter.h>
Public Member Functions | |
BasicBloomFilter (size_t items_estimate, float false_positive_prob) | |
Constructor. More... | |
BasicBloomFilter (size_t items_estimate, float bits_per_item, size_t num_hashes) | |
Alternative constructor. More... | |
BasicBloomFilter (size_t items_estimate, size_t items_actual, int64_t length, size_t num_hashes) | |
Alternative constructor. More... | |
~BasicBloomFilter () | |
Destructor; releases resources. More... | |
void | insert (const void *key, size_t len) |
Inserts a new blob into the hash. More... | |
void | insert (const String &key) |
Overloaded insert function for Strings. More... | |
bool | may_contain (const void *key, size_t len) const |
Checks if the data set "may" contain the key. More... | |
bool | may_contain (const String &key) const |
Overloaded may_contain function for Strings. More... | |
void | serialize (StaticBuffer &buf) |
Serializes the BloomFilter into a static memory buffer. More... | |
uint8_t * | ptr () |
Getter for the bloom filter data. More... | |
size_t | size () |
Getter for the bloom filter size. More... | |
size_t | get_num_hashes () |
Getter for the number of hash functions. More... | |
size_t | get_length_bits () |
Getter for the number of bits. More... | |
size_t | get_items_estimate () |
Getter for the estimated number of items. More... | |
size_t | get_items_actual () |
Getter for the actual number of items. More... | |
Private Attributes | |
HasherT | m_hasher |
The hash function implementation. More... | |
size_t | m_items_estimate |
Estimated number of items. More... | |
size_t | m_items_actual |
Actual number of items. More... | |
float | m_false_positive_prob |
Probability of returning a false positive. More... | |
size_t | m_num_hash_functions |
Number of hash functions. More... | |
size_t | m_num_bits |
Number of bits. More... | |
size_t | m_num_bytes |
Number of bytes (approx. More... | |
uint8_t * | m_bloom_bits |
The actual bloom filter bit-array. More... | |
A space-efficent probabilistic set for membership test, false postives are possible, but false negatives are not.
Definition at line 50 of file BloomFilter.h.
|
inline |
Constructor.
items_estimate | An estimated number of items that will be inserted |
false_positive_prob | The probability for false positives |
Definition at line 58 of file BloomFilter.h.
|
inline |
Alternative constructor.
items_estimate | An estimated number of items that will be inserted |
bits_per_item | Average bits per item |
num_hashes | Number of hash functions for the filter |
Definition at line 88 of file BloomFilter.h.
|
inline |
Alternative constructor.
items_estimate | An estimated number of items that will be inserted |
items_actual | Actual number of items |
length | Number of bits |
num_hashes | Number of hash functions for the filter |
Definition at line 117 of file BloomFilter.h.
|
inline |
Destructor; releases resources.
Definition at line 141 of file BloomFilter.h.
|
inline |
Getter for the actual number of items.
Definition at line 256 of file BloomFilter.h.
|
inline |
Getter for the estimated number of items.
Definition at line 250 of file BloomFilter.h.
|
inline |
Getter for the number of bits.
Definition at line 244 of file BloomFilter.h.
|
inline |
Getter for the number of hash functions.
Definition at line 238 of file BloomFilter.h.
|
inline |
Inserts a new blob into the hash.
Runs through each hash function and sets the appropriate bit for each hash.
key | Pointer to the key's data |
len | Size of the data (in bytes) |
Definition at line 159 of file BloomFilter.h.
|
inline |
Overloaded insert function for Strings.
key | Reference to the string. |
Definition at line 173 of file BloomFilter.h.
|
inline |
Checks if the data set "may" contain the key.
This can return false positives.
This function runs through all hash tables and checks if the hashed bit is set. If any of them is not set then the key is definitely not part of the data set. If all bits are set then the key "may" be in the data set.
key | Pointer to the key's data |
len | Size of the data (in bytes) |
Definition at line 188 of file BloomFilter.h.
|
inline |
Overloaded may_contain function for Strings.
key | The String to look for |
Definition at line 210 of file BloomFilter.h.
|
inline |
Getter for the bloom filter data.
Definition at line 226 of file BloomFilter.h.
|
inline |
Serializes the BloomFilter into a static memory buffer.
buf | The static memory buffer |
Definition at line 218 of file BloomFilter.h.
|
inline |
Getter for the bloom filter size.
Definition at line 232 of file BloomFilter.h.
|
private |
The actual bloom filter bit-array.
Definition at line 281 of file BloomFilter.h.
|
private |
Probability of returning a false positive.
Definition at line 269 of file BloomFilter.h.
|
private |
The hash function implementation.
Definition at line 260 of file BloomFilter.h.
|
private |
Actual number of items.
Definition at line 266 of file BloomFilter.h.
|
private |
Estimated number of items.
Definition at line 263 of file BloomFilter.h.
|
private |
Number of bits.
Definition at line 275 of file BloomFilter.h.
|
private |
|
private |
Number of hash functions.
Definition at line 272 of file BloomFilter.h.