From 83ce77e575cc99d1d922ca5bd6f47204e8ffd62e Mon Sep 17 00:00:00 2001 From: Bernhard Amann Date: Tue, 30 Jul 2013 18:48:05 -0700 Subject: [PATCH] re-use same hash class for all add operations --- src/OpaqueVal.cc | 8 ++++++++ src/OpaqueVal.h | 2 ++ src/probabilistic/hyper-loglog.bif | 15 +-------------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index e2e7e4f967..dcf3e84430 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -771,3 +771,11 @@ BroType* CardinalityVal::Type() const { return type; } + +void CardinalityVal::Add(const Val* val) + { + HashKey* key = hash->ComputeHash(val, 1); + c->addElement(key->Hash()); + delete key; + } + diff --git a/src/OpaqueVal.h b/src/OpaqueVal.h index 3a4b548308..a7c51657c4 100644 --- a/src/OpaqueVal.h +++ b/src/OpaqueVal.h @@ -154,6 +154,8 @@ public: explicit CardinalityVal(probabilistic::CardinalityCounter*); virtual ~CardinalityVal(); + void Add(const Val* val); + BroType* Type() const; bool Typify(BroType* type); diff --git a/src/probabilistic/hyper-loglog.bif b/src/probabilistic/hyper-loglog.bif index 012b2d2988..6e69e70735 100644 --- a/src/probabilistic/hyper-loglog.bif +++ b/src/probabilistic/hyper-loglog.bif @@ -54,20 +54,7 @@ function hll_cardinality_add%(handle: opaque of cardinality, elem: any%): bool return new Val(0, TYPE_BOOL); } - int status = 0; - - TypeList* tl = new TypeList(elem->Type()); - tl->Append(elem->Type()); - CompositeHash* hll_hash = new CompositeHash(tl); - Unref(tl); - - HashKey* key = hll_hash->ComputeHash(elem, 1); - uint64_t hash = key->Hash(); - - CardinalityCounter* h = cv->Get(); - h->addElement(hash); - - delete hll_hash; + cv->Add(elem); return new Val(1, TYPE_BOOL); %}