Merge remote-tracking branch 'origin/topic/matthias/bloom-filter'

I'm moving the new files into a subdirectory probabilistic, and into a
corresponding namespace. We can later put code for the other
probabilistic data structures there as well.

* origin/topic/matthias/bloom-filter: (45 commits)
  Implement and test Bloom filter merging.
  Make hash functions equality comparable.
  Make counter vectors mergeable.
  Use half adder for bitwise addition and subtraction.
  Fix and test counting Bloom filter.
  Implement missing CounterVector functions.
  Tweak hasher interface.
  Add missing include for GCC.
  Fixing for unserializion error.
  Small fixes and style tweaks.
  Only serialize Bloom filter type if available.
  Create hash policies through factory.
  Remove lingering debug code.
  Factor implementation and change interface.
  Expose Bro's linear congruence PRNG as utility function.
  H3 does not check for zero length input.
  Support seeding for hashers.
  Add utility function to access first random seed.
  Update H3 documentation (and minor style nits.)
  Make H3 seed configurable.
  ...
This commit is contained in:
Robin Sommer 2013-07-23 16:40:56 -07:00
commit 21685d2529
26 changed files with 2279 additions and 67 deletions

View file

@ -3,10 +3,18 @@
#ifndef OPAQUEVAL_H
#define OPAQUEVAL_H
#include <typeinfo>
#include "RandTest.h"
#include "Val.h"
#include "digest.h"
#include "probabilistic/BloomFilter.h"
namespace probabilistic {
class BloomFilter;
}
class HashVal : public OpaqueVal {
public:
virtual bool IsValid() const;
@ -107,4 +115,56 @@ private:
RandTest state;
};
class BloomFilterVal : public OpaqueVal {
BloomFilterVal(const BloomFilterVal&);
BloomFilterVal& operator=(const BloomFilterVal&);
public:
static BloomFilterVal* Merge(const BloomFilterVal* x,
const BloomFilterVal* y);
explicit BloomFilterVal(probabilistic::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:
template <typename T>
static BloomFilterVal* DoMerge(const BloomFilterVal* x,
const BloomFilterVal* y)
{
if ( typeid(*x->bloom_filter_) != typeid(*y->bloom_filter_) )
{
reporter->InternalError("cannot merge different Bloom filter types");
return NULL;
}
if ( typeid(T) != typeid(*x->bloom_filter_) )
return NULL;
const T* a = static_cast<const T*>(x->bloom_filter_);
const T* b = static_cast<const T*>(y->bloom_filter_);
BloomFilterVal* merged = new BloomFilterVal(T::Merge(a, b));
assert(merged);
if ( ! merged->Typify(x->Type()) )
{
reporter->InternalError("failed to set type on merged Bloom filter");
return NULL;
}
return merged;
}
BroType* type_;
CompositeHash* hash_;
probabilistic::BloomFilter* bloom_filter_;
};
#endif