Skip to content

Commit 9c34731

Browse files
committed
CBloomFilter::clear() method
1 parent cdb4193 commit 9c34731

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/bloom.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ bool CBloomFilter::contains(const uint256& hash) const
9494
return contains(data);
9595
}
9696

97+
void CBloomFilter::clear()
98+
{
99+
vData.assign(vData.size(),0);
100+
isFull = false;
101+
isEmpty = true;
102+
}
103+
97104
bool CBloomFilter::IsWithinSizeConstraints() const
98105
{
99106
return vData.size() <= MAX_BLOOM_FILTER_SIZE && nHashFuncs <= MAX_HASH_FUNCS;

src/bloom.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class CBloomFilter
7878
bool contains(const COutPoint& outpoint) const;
7979
bool contains(const uint256& hash) const;
8080

81+
void clear();
82+
8183
// True if the size is <= MAX_BLOOM_FILTER_SIZE and the number of hash functions is <= MAX_HASH_FUNCS
8284
// (catch a filter which was just deserialized which was too big)
8385
bool IsWithinSizeConstraints() const;

src/test/bloom_tests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize)
4545
expected[i] = (char)vch[i];
4646

4747
BOOST_CHECK_EQUAL_COLLECTIONS(stream.begin(), stream.end(), expected.begin(), expected.end());
48+
49+
BOOST_CHECK_MESSAGE( filter.contains(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "BloomFilter doesn't contain just-inserted object!");
50+
filter.clear();
51+
BOOST_CHECK_MESSAGE( !filter.contains(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "BloomFilter should be empty!");
4852
}
4953

5054
BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize_with_tweak)

0 commit comments

Comments
 (0)