mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-12 12:52:35 -03:00
Fix bloom filter not to use bit_mask
This commit is contained in:
parent
98f4c6c49c
commit
b1b9c76262
1 changed files with 2 additions and 4 deletions
|
@ -15,8 +15,6 @@
|
||||||
|
|
||||||
using namespace std;
|
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) :
|
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:
|
// 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
|
// - nElements * log(fp rate) / ln(2)^2
|
||||||
|
@ -47,7 +45,7 @@ void CBloomFilter::insert(const vector<unsigned char>& vKey)
|
||||||
{
|
{
|
||||||
unsigned int nIndex = Hash(i, vKey);
|
unsigned int nIndex = Hash(i, vKey);
|
||||||
// Sets bit nIndex of vData
|
// Sets bit nIndex of vData
|
||||||
vData[nIndex >> 3] |= bit_mask[7 & nIndex];
|
vData[nIndex >> 3] |= (1 << (7 & nIndex));
|
||||||
}
|
}
|
||||||
isEmpty = false;
|
isEmpty = false;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +74,7 @@ bool CBloomFilter::contains(const vector<unsigned char>& vKey) const
|
||||||
{
|
{
|
||||||
unsigned int nIndex = Hash(i, vKey);
|
unsigned int nIndex = Hash(i, vKey);
|
||||||
// Checks bit nIndex of vData
|
// Checks bit nIndex of vData
|
||||||
if (!(vData[nIndex >> 3] & bit_mask[7 & nIndex]))
|
if (!(vData[nIndex >> 3] & (1 << (7 & nIndex))))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue