aboutsummaryrefslogtreecommitdiff
path: root/src/bloom.cpp
diff options
context:
space:
mode:
authorPeter Todd <pete@petertodd.org>2015-07-17 06:42:43 -0400
committerPieter Wuille <pieter.wuille@gmail.com>2015-07-27 18:37:18 +0200
commitbbe41088c61f2ad328766e851ffe6169aa80935a (patch)
treec8b48b4f462dccfd11b31d3270b5f9e7123ec40c /src/bloom.cpp
parent08e9c57ba2aa808c608daa0b4503f1940a356f8c (diff)
downloadbitcoin-bbe41088c61f2ad328766e851ffe6169aa80935a.tar.xz
Add uint256 support to CRollingBloomFilter
Diffstat (limited to 'src/bloom.cpp')
-rw-r--r--src/bloom.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/bloom.cpp b/src/bloom.cpp
index 36cba491c4..e15bc32f97 100644
--- a/src/bloom.cpp
+++ b/src/bloom.cpp
@@ -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
{
if (nInsertions < nBloomSize / 2) {
@@ -242,6 +256,14 @@ bool CRollingBloomFilter::contains(const std::vector<unsigned char>& vKey) const
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()
{
b1.clear();