mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
Associate a Comphash with a BloomFilterVal.
We also keep track of the Bloom filter's element type inside each value. The first use of the BiF bloomfilter_add will "typify" the Bloom filter and lock the Bloom filter's type to the element type.
This commit is contained in:
parent
751cf61293
commit
880d02f720
4 changed files with 91 additions and 5 deletions
|
@ -199,6 +199,21 @@ size_t BasicBloomFilter::CountImpl(const HashPolicy::HashVector& h) const
|
|||
return 1;
|
||||
}
|
||||
|
||||
CountingBloomFilter::CountingBloomFilter(double fp, size_t capacity,
|
||||
size_t width)
|
||||
: BloomFilter(BasicBloomFilter::K(BasicBloomFilter::M(fp, capacity),
|
||||
capacity))
|
||||
{
|
||||
cells_ = new CounterVector(width, BasicBloomFilter::M(fp, capacity));
|
||||
}
|
||||
|
||||
CountingBloomFilter::CountingBloomFilter(size_t cells, size_t capacity,
|
||||
size_t width)
|
||||
: BloomFilter(BasicBloomFilter::K(cells, capacity))
|
||||
{
|
||||
cells_ = new CounterVector(width, cells);
|
||||
}
|
||||
|
||||
|
||||
IMPLEMENT_SERIAL(CountingBloomFilter, SER_COUNTINGBLOOMFILTER)
|
||||
|
||||
|
|
|
@ -269,7 +269,8 @@ private:
|
|||
*/
|
||||
class CountingBloomFilter : public BloomFilter {
|
||||
public:
|
||||
CountingBloomFilter(unsigned width);
|
||||
CountingBloomFilter(double fp, size_t capacity, size_t width);
|
||||
CountingBloomFilter(size_t cells, size_t capacity, size_t width);
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(CountingBloomFilter);
|
||||
|
|
|
@ -518,31 +518,87 @@ bool EntropyVal::DoUnserialize(UnserialInfo* info)
|
|||
return true;
|
||||
}
|
||||
|
||||
BloomFilterVal::BloomFilterVal() : OpaqueVal(bloomfilter_type)
|
||||
BloomFilterVal::BloomFilterVal(BloomFilter* bf)
|
||||
: OpaqueVal(bloomfilter_type), bloom_filter_(bf)
|
||||
{
|
||||
}
|
||||
|
||||
BloomFilterVal::BloomFilterVal(OpaqueType* t) : OpaqueVal(t)
|
||||
BloomFilterVal::BloomFilterVal(OpaqueType* t)
|
||||
: OpaqueVal(t)
|
||||
{
|
||||
}
|
||||
|
||||
bool BloomFilterVal::Typify(BroType* type)
|
||||
{
|
||||
if ( type_ )
|
||||
return false;
|
||||
type_ = type;
|
||||
TypeList* tl = new TypeList(type_);
|
||||
tl->Append(type_);
|
||||
hash_ = new CompositeHash(tl);
|
||||
Unref(tl);
|
||||
return true;
|
||||
}
|
||||
|
||||
BroType* BloomFilterVal::Type() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
void BloomFilterVal::Add(const Val* val)
|
||||
{
|
||||
HashKey* key = hash_->ComputeHash(val, 1);
|
||||
bloom_filter_->Add(key->Hash());
|
||||
}
|
||||
|
||||
size_t BloomFilterVal::Count(const Val* val) const
|
||||
{
|
||||
HashKey* key = hash_->ComputeHash(val, 1);
|
||||
return bloom_filter_->Count(key->Hash());
|
||||
}
|
||||
|
||||
BloomFilterVal* BloomFilterVal::Merge(const BloomFilterVal* first,
|
||||
const BloomFilterVal* second)
|
||||
{
|
||||
assert(! "not yet implemented");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BloomFilterVal::~BloomFilterVal()
|
||||
{
|
||||
if ( type_ )
|
||||
Unref(type_);
|
||||
if ( hash_ )
|
||||
delete hash_;
|
||||
if ( bloom_filter_ )
|
||||
delete bloom_filter_;
|
||||
}
|
||||
|
||||
BloomFilterVal::BloomFilterVal()
|
||||
: OpaqueVal(bloomfilter_type)
|
||||
{
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(BloomFilterVal, SER_BLOOMFILTER_VAL);
|
||||
|
||||
bool BloomFilterVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BLOOMFILTER_VAL, OpaqueVal);
|
||||
if ( ! SERIALIZE(type_) )
|
||||
return false;
|
||||
return SERIALIZE(bloom_filter_);
|
||||
}
|
||||
|
||||
bool BloomFilterVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal);
|
||||
type_ = BroType::Unserialize(info);
|
||||
if ( ! type_ )
|
||||
return false;
|
||||
TypeList* tl = new TypeList(type_);
|
||||
tl->Append(type_);
|
||||
hash_ = new CompositeHash(tl);
|
||||
Unref(tl);
|
||||
bloom_filter_ = BloomFilter::Unserialize(info);
|
||||
return bloom_filter_ == NULL;
|
||||
}
|
||||
|
|
|
@ -110,18 +110,32 @@ private:
|
|||
};
|
||||
|
||||
class BloomFilterVal : public OpaqueVal {
|
||||
BloomFilterVal(const BloomFilterVal&);
|
||||
BloomFilterVal& operator=(const BloomFilterVal&);
|
||||
public:
|
||||
BloomFilterVal();
|
||||
static BloomFilterVal* Merge(const BloomFilterVal* first,
|
||||
const BloomFilterVal* second);
|
||||
|
||||
BloomFilterVal(BloomFilter* bf);
|
||||
~BloomFilterVal();
|
||||
|
||||
bool Typify(BroType* type);
|
||||
BroType* Type() const;
|
||||
|
||||
void Add(const Val* val);
|
||||
size_t Count(const Val* val) const;
|
||||
|
||||
protected:
|
||||
friend class Val;
|
||||
BloomFilterVal();
|
||||
BloomFilterVal(OpaqueType* t);
|
||||
|
||||
DECLARE_SERIAL(BloomFilterVal);
|
||||
|
||||
private:
|
||||
BloomFilter* bloom_filter_;
|
||||
BroType* type_;
|
||||
CompositeHash* hash_;
|
||||
BloomFilter* bloom_filter_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue