Skip to content

Commit 8562179

Browse files
committed
Merge pull request #3912
b1b9c76 Fix bloom filter not to use bit_mask (peryaudo)
2 parents 9c749d6 + b1b9c76 commit 8562179

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/bloom.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
using namespace std;
1717

18-
static const unsigned char bit_mask[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
19-
2018
CBloomFilter::CBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweakIn, unsigned char nFlagsIn) :
2119
// The ideal size for a bloom filter with a given number of elements and false positive rate is:
2220
// - nElements * log(fp rate) / ln(2)^2
@@ -47,7 +45,7 @@ void CBloomFilter::insert(const vector<unsigned char>& vKey)
4745
{
4846
unsigned int nIndex = Hash(i, vKey);
4947
// Sets bit nIndex of vData
50-
vData[nIndex >> 3] |= bit_mask[7 & nIndex];
48+
vData[nIndex >> 3] |= (1 << (7 & nIndex));
5149
}
5250
isEmpty = false;
5351
}
@@ -76,7 +74,7 @@ bool CBloomFilter::contains(const vector<unsigned char>& vKey) const
7674
{
7775
unsigned int nIndex = Hash(i, vKey);
7876
// Checks bit nIndex of vData
79-
if (!(vData[nIndex >> 3] & bit_mask[7 & nIndex]))
77+
if (!(vData[nIndex >> 3] & (1 << (7 & nIndex))))
8078
return false;
8179
}
8280
return true;

0 commit comments

Comments
 (0)