From 9c347313f7f504d602a9d744f1ad7aee4e3d6f9a Mon Sep 17 00:00:00 2001 From: Tom Harding Date: Mon, 21 Jul 2014 11:50:07 -0700 Subject: [PATCH] CBloomFilter::clear() method --- src/bloom.cpp | 7 +++++++ src/bloom.h | 2 ++ src/test/bloom_tests.cpp | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/src/bloom.cpp b/src/bloom.cpp index 26e366179ca..85a2ddc1892 100644 --- a/src/bloom.cpp +++ b/src/bloom.cpp @@ -94,6 +94,13 @@ bool CBloomFilter::contains(const uint256& hash) const return contains(data); } +void CBloomFilter::clear() +{ + vData.assign(vData.size(),0); + isFull = false; + isEmpty = true; +} + bool CBloomFilter::IsWithinSizeConstraints() const { return vData.size() <= MAX_BLOOM_FILTER_SIZE && nHashFuncs <= MAX_HASH_FUNCS; diff --git a/src/bloom.h b/src/bloom.h index 956bead87f8..d0caf9e9faf 100644 --- a/src/bloom.h +++ b/src/bloom.h @@ -78,6 +78,8 @@ public: bool contains(const COutPoint& outpoint) const; bool contains(const uint256& hash) const; + void clear(); + // True if the size is <= MAX_BLOOM_FILTER_SIZE and the number of hash functions is <= MAX_HASH_FUNCS // (catch a filter which was just deserialized which was too big) bool IsWithinSizeConstraints() const; diff --git a/src/test/bloom_tests.cpp b/src/test/bloom_tests.cpp index 69de3b5bb19..2cdafa4bdde 100644 --- a/src/test/bloom_tests.cpp +++ b/src/test/bloom_tests.cpp @@ -45,6 +45,10 @@ BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize) expected[i] = (char)vch[i]; BOOST_CHECK_EQUAL_COLLECTIONS(stream.begin(), stream.end(), expected.begin(), expected.end()); + + BOOST_CHECK_MESSAGE( filter.contains(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "BloomFilter doesn't contain just-inserted object!"); + filter.clear(); + BOOST_CHECK_MESSAGE( !filter.contains(ParseHex("99108ad8ed9bb6274d3980bab5a85c048f0950c8")), "BloomFilter should be empty!"); } BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize_with_tweak)