Skip to content

Commit

Permalink
Reuse vector hashing code for uint256
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa authored and Fuzzbawls committed Jun 23, 2020
1 parent 3230143 commit dcd15bc
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,8 @@ 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;
}
std::vector<unsigned char> data(hash.begin(), hash.end());
insert(data);
}

bool CRollingBloomFilter::contains(const std::vector<unsigned char>& vKey) const
Expand All @@ -304,10 +296,8 @@ bool CRollingBloomFilter::contains(const std::vector<unsigned char>& vKey) const

bool CRollingBloomFilter::contains(const uint256& hash) const
{
if (nInsertions < nBloomSize / 2) {
return b2.contains(hash);
}
return b1.contains(hash);
std::vector<unsigned char> data(hash.begin(), hash.end());
return contains(data);
}

void CRollingBloomFilter::clear()
Expand Down

0 comments on commit dcd15bc

Please sign in to comment.