CBloomFilter::CBloomFilter(const unsigned int nElements, const double nFPRate, const unsigned int nTweakIn, unsigned char nFlagsIn) :
vData(std::min((unsigned int)(-1 / LN2SQUARED * nElements * log(nFPRate)), MAX_BLOOM_FILTER_SIZE * 8) / 8),
* Again, we ignore filter parameters which will create a bloom filter with more hash functions than the protocol limits
inline unsigned int CBloomFilter::Hash(unsigned int nHashNum, Span<const unsigned char> vDataToHash) const
// is discovered in order to find spending transactions, which avoids round-tripping and race conditions.
/* In this rolling bloom filter, we'll store between 2 and 3 generations of nElements / 2 entries. */
uint32_t nFilterBits = (uint32_t)ceil(-1.0 * nHashFuncs * nMaxElements / log(1.0 - exp(logFpRate / nHashFuncs)));
static inline uint32_t RollingBloomHash(unsigned int nHashNum, uint32_t nTweak, Span<const unsigned char> vDataToHash)
/* FastMod works with the upper bits of h, so it is safe to ignore that the lower bits of h are already used for bit. */
/* The lowest bit of pos is ignored, and set to zero for the first bit, and to one for the second. */
data[pos & ~1U] = (data[pos & ~1U] & ~(uint64_t{1} << bit)) | (uint64_t(nGeneration & 1)) << bit;
/* If the relevant bit is not set in either data[pos & ~1] or data[pos | 1], the filter does not contain vKey */