mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 23:58:20 +00:00
Add bloomfilter_clear() BiF.
This commit is contained in:
parent
c89f61917b
commit
5383e8f75b
7 changed files with 53 additions and 0 deletions
|
@ -578,6 +578,11 @@ size_t BloomFilterVal::Count(const Val* val) const
|
|||
return cnt;
|
||||
}
|
||||
|
||||
void BloomFilterVal::Clear()
|
||||
{
|
||||
bloom_filter->Clear();
|
||||
}
|
||||
|
||||
BloomFilterVal* BloomFilterVal::Merge(const BloomFilterVal* x,
|
||||
const BloomFilterVal* y)
|
||||
{
|
||||
|
|
|
@ -125,6 +125,7 @@ public:
|
|||
|
||||
void Add(const Val* val);
|
||||
size_t Count(const Val* val) const;
|
||||
void Clear();
|
||||
|
||||
static BloomFilterVal* Merge(const BloomFilterVal* x,
|
||||
const BloomFilterVal* y);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue