Add uint256 support to CRollingBloomFilter
This commit is contained in:
parent
08e9c57ba2
commit
bbe41088c6
@ -234,6 +234,20 @@ void CRollingBloomFilter::insert(const std::vector<unsigned char>& vKey)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CRollingBloomFilter::insert(const uint256& hash)
|
||||||
|
{
|
||||||
|
if (nInsertions == 0) {
|
||||||
|
b1.clear();
|
||||||
|
} else if (nInsertions == nBloomSize / 2) {
|
||||||
|
b2.clear();
|
||||||
|
}
|
||||||
|
b1.insert(hash);
|
||||||
|
b2.insert(hash);
|
||||||
|
if (++nInsertions == nBloomSize) {
|
||||||
|
nInsertions = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CRollingBloomFilter::contains(const std::vector<unsigned char>& vKey) const
|
bool CRollingBloomFilter::contains(const std::vector<unsigned char>& vKey) const
|
||||||
{
|
{
|
||||||
if (nInsertions < nBloomSize / 2) {
|
if (nInsertions < nBloomSize / 2) {
|
||||||
@ -242,6 +256,14 @@ bool CRollingBloomFilter::contains(const std::vector<unsigned char>& vKey) const
|
|||||||
return b1.contains(vKey);
|
return b1.contains(vKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CRollingBloomFilter::contains(const uint256& hash) const
|
||||||
|
{
|
||||||
|
if (nInsertions < nBloomSize / 2) {
|
||||||
|
return b2.contains(hash);
|
||||||
|
}
|
||||||
|
return b1.contains(hash);
|
||||||
|
}
|
||||||
|
|
||||||
void CRollingBloomFilter::clear()
|
void CRollingBloomFilter::clear()
|
||||||
{
|
{
|
||||||
b1.clear();
|
b1.clear();
|
||||||
|
@ -114,7 +114,9 @@ public:
|
|||||||
CRollingBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweak);
|
CRollingBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweak);
|
||||||
|
|
||||||
void insert(const std::vector<unsigned char>& vKey);
|
void insert(const std::vector<unsigned char>& vKey);
|
||||||
|
void insert(const uint256& hash);
|
||||||
bool contains(const std::vector<unsigned char>& vKey) const;
|
bool contains(const std::vector<unsigned char>& vKey) const;
|
||||||
|
bool contains(const uint256& hash) const;
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user