diff --git a/src/bloom.h b/src/bloom.h --- a/src/bloom.h +++ b/src/bloom.h @@ -55,7 +55,8 @@ const std::vector &vDataToHash) const; // Private constructor for CRollingBloomFilter, no restrictions on size - CBloomFilter(uint32_t nElements, double nFPRate, uint32_t nTweak); + CBloomFilter(const uint32_t nElements, const double nFPRate, + const uint32_t nTweak); friend class CRollingBloomFilter; public: @@ -70,8 +71,8 @@ * always be a random value (and is largely only exposed for unit testing) * nFlags should be one of the BLOOM_UPDATE_* enums (not _MASK) */ - CBloomFilter(uint32_t nElements, double nFPRate, uint32_t nTweak, - uint8_t nFlagsIn); + CBloomFilter(const uint32_t nElements, const double nFPRate, + const uint32_t nTweak, uint8_t nFlagsIn); CBloomFilter() : isFull(true), isEmpty(false), nHashFuncs(0), nTweak(0), nFlags(0) {} @@ -94,7 +95,7 @@ bool contains(const uint256 &hash) const; void clear(); - void reset(uint32_t nNewTweak); + void reset(const uint32_t nNewTweak); //! True if the size is <= MAX_BLOOM_FILTER_SIZE and the number of hash //! functions is <= MAX_HASH_FUNCS (catch a filter which was just @@ -140,7 +141,7 @@ // A random bloom filter calls GetRand() at creation time. Don't create // global CRollingBloomFilter objects, as they may be constructed before the // randomizer is properly initialized. - CRollingBloomFilter(uint32_t nElements, double nFPRate); + CRollingBloomFilter(const uint32_t nElements, const double nFPRate); void insert(const std::vector &vKey); void insert(const uint256 &hash); diff --git a/src/bloom.cpp b/src/bloom.cpp --- a/src/bloom.cpp +++ b/src/bloom.cpp @@ -30,8 +30,8 @@ * See https://en.wikipedia.org/wiki/Bloom_filter for an explanation of these * formulas. */ -CBloomFilter::CBloomFilter(uint32_t nElements, double nFPRate, - uint32_t nTweakIn, uint8_t nFlagsIn) +CBloomFilter::CBloomFilter(const uint32_t nElements, const double nFPRate, + const uint32_t nTweakIn, uint8_t nFlagsIn) : vData(std::min(-1 / LN2SQUARED * nElements * log(nFPRate), MAX_BLOOM_FILTER_SIZE * 8) / 8), @@ -41,8 +41,8 @@ nTweak(nTweakIn), nFlags(nFlagsIn) {} // Private constructor used by CRollingBloomFilter -CBloomFilter::CBloomFilter(uint32_t nElements, double nFPRate, - uint32_t nTweakIn) +CBloomFilter::CBloomFilter(const uint32_t nElements, const double nFPRate, + const uint32_t nTweakIn) : vData(uint32_t(-1 / LN2SQUARED * nElements * log(nFPRate)) / 8), isFull(false), isEmpty(true), nHashFuncs(uint32_t(vData.size() * 8 / nElements * LN2)), @@ -117,7 +117,7 @@ isEmpty = true; } -void CBloomFilter::reset(uint32_t nNewTweak) { +void CBloomFilter::reset(const uint32_t nNewTweak) { clear(); nTweak = nNewTweak; } @@ -219,7 +219,8 @@ isEmpty = empty; } -CRollingBloomFilter::CRollingBloomFilter(uint32_t nElements, double fpRate) { +CRollingBloomFilter::CRollingBloomFilter(const uint32_t nElements, + const double fpRate) { double logFpRate = log(fpRate); /* The optimal number of hash functions is log(fpRate) / log(0.5), but * restrict it to the range 1-50. */