Bitcoin Core 28.99.0
P2P Digital Currency
|
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set. More...
#include <bloom.h>
Public Member Functions | |
CRollingBloomFilter (const unsigned int nElements, const double nFPRate) | |
void | insert (Span< const unsigned char > vKey) |
bool | contains (Span< const unsigned char > vKey) const |
void | reset () |
Private Attributes | |
int | nEntriesPerGeneration |
int | nEntriesThisGeneration |
int | nGeneration |
std::vector< uint64_t > | data |
unsigned int | nTweak |
int | nHashFuncs |
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Construct it with the number of items to keep track of, and a false-positive rate. Unlike CBloomFilter, by default nTweak is set to a cryptographically secure random value for you. Similarly rather than clear() the method reset() is provided, which also changes nTweak to decrease the impact of false-positives.
contains(item) will always return true if item was one of the last N to 1.5*N insert()'ed ... but may also return true for items that were not inserted.
It needs around 1.8 bytes per element per factor 0.1 of false positive rate. For example, if we want 1000 elements, we'd need:
If we make these simplifying assumptions:
Then we get a more accurate estimate for filter bytes:
3/(log(256)*log(2)) * log(1/fpRate) * nElements
CRollingBloomFilter::CRollingBloomFilter | ( | const unsigned int | nElements, |
const double | nFPRate | ||
) |
bool CRollingBloomFilter::contains | ( | Span< const unsigned char > | vKey | ) | const |
void CRollingBloomFilter::insert | ( | Span< const unsigned char > | vKey | ) |
void CRollingBloomFilter::reset | ( | ) |