From b1b9c762623c392ac665ecdc315e1d2073eaac43 Mon Sep 17 00:00:00 2001 From: peryaudo Date: Thu, 20 Mar 2014 13:21:23 +0900 Subject: [PATCH] Fix bloom filter not to use bit_mask --- src/bloom.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/bloom.cpp b/src/bloom.cpp index cbb8cf4a8..1bfcbd406 100644 --- a/src/bloom.cpp +++ b/src/bloom.cpp @@ -15,8 +15,6 @@ using namespace std; -static const unsigned char bit_mask[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; - CBloomFilter::CBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweakIn, unsigned char nFlagsIn) : // The ideal size for a bloom filter with a given number of elements and false positive rate is: // - nElements * log(fp rate) / ln(2)^2 @@ -47,7 +45,7 @@ void CBloomFilter::insert(const vector& vKey) { unsigned int nIndex = Hash(i, vKey); // Sets bit nIndex of vData - vData[nIndex >> 3] |= bit_mask[7 & nIndex]; + vData[nIndex >> 3] |= (1 << (7 & nIndex)); } isEmpty = false; } @@ -76,7 +74,7 @@ bool CBloomFilter::contains(const vector& vKey) const { unsigned int nIndex = Hash(i, vKey); // Checks bit nIndex of vData - if (!(vData[nIndex >> 3] & bit_mask[7 & nIndex])) + if (!(vData[nIndex >> 3] & (1 << (7 & nIndex)))) return false; } return true;