Add bloomfilter_clear() BiF.

This commit is contained in:
Matthias Vallentin 2013-07-24 11:21:10 +02:00
parent c89f61917b
commit 5383e8f75b
7 changed files with 53 additions and 0 deletions

View file

@ -74,6 +74,11 @@ size_t BasicBloomFilter::K(size_t cells, size_t capacity)
return std::ceil(frac * std::log(2));
}
void BasicBloomFilter::Clear()
{
bits->Clear();
}
BasicBloomFilter* BasicBloomFilter::Merge(const BasicBloomFilter* x,
const BasicBloomFilter* y)
{
@ -191,3 +196,8 @@ size_t CountingBloomFilter::CountImpl(const Hasher::digest_vector& h) const
return min;
}
void CountingBloomFilter::Clear()
{
cells->Clear();
}

View file

@ -47,6 +47,11 @@ public:
return CountImpl((*hasher)(x));
}
/**
* Removes all elements, i.e., resets all bits in the underlying bit vector.
*/
virtual void Clear() = 0;
/**
* Serializes the Bloom filter.
*
@ -147,6 +152,9 @@ public:
*/
static size_t K(size_t cells, size_t capacity);
// Overridden from BloomFilter.
virtual void Clear();
/**
* Merges two basic Bloom filters.
*
@ -188,6 +196,9 @@ public:
*/
CountingBloomFilter(const Hasher* hasher, size_t cells, size_t width);
// Overridden from BloomFilter.
virtual void Clear();
/**
* Merges two counting Bloom filters.
*

View file

@ -70,6 +70,11 @@ bool CounterVector::Decrement(size_type cell, count_type value)
return carry;
}
void CounterVector::Clear()
{
bits->Clear();
}
CounterVector::count_type CounterVector::Count(size_type cell) const
{
assert(cell < Size());

View file

@ -77,6 +77,11 @@ public:
*/
count_type Count(size_type cell) const;
/**
* Sets all counters to 0.
*/
void Clear();
/**
* Retrieves the number of cells in the storage.
*

View file

@ -121,6 +121,22 @@ function bloomfilter_lookup%(bf: opaque of bloomfilter, x: any%): count
return new Val(0, TYPE_COUNT);
%}
## Removes all elements from a Bloom filter. This function sets resets all bits
## in the underlying bitvector to 0 but does not change the parameterization of
## the Bloom filter, such as the element type and the hasher seed.
##
## bf: The Bloom filter handle.
function bloomfilter_clear%(bf: opaque of bloomfilter%): any
%{
BloomFilterVal* bfv = static_cast<BloomFilterVal*>(bf);
if ( bfv->Type() ) // Untyped Bloom filters are already empty.
bfv->Clear();
return 0;
%}
## Merges two Bloom filters.
##
## bf1: The first Bloom filter handle.