ok, this bug was hard to find.

hyperloglog.h was missing guards and randomly deleting memory at
addresses equal to variable contents.

I am not entirely sure why that did not crash before...
This commit is contained in:
Bernhard Amann 2013-04-10 13:45:21 -04:00
parent a37ffab0ea
commit 240d667e30
4 changed files with 17 additions and 12 deletions

View file

@ -18,7 +18,7 @@ int CardinalityCounter::optimalB(double error)
answer++;
k = pow(2, (answer - initial_estimate)/2);
}
while (erf(k/sqrt(2)) < conf);
while (erf(k/sqrt(2)) < HLL_CONF);
return answer;
}
@ -67,9 +67,6 @@ CardinalityCounter :: CardinalityCounter(double error_margin)
CardinalityCounter::~CardinalityCounter()
{
delete [] buckets;
delete &m;
delete &V;
delete &alpha_m;
}
uint8_t CardinalityCounter::rank(uint64_t hash_modified)

View file

@ -1,16 +1,19 @@
// See the file "COPYING" in the main distribution directory for copyright.
#ifndef hyperloglog_h
#define hyperloglog_h
#include <stdint.h>
#include <opaqueval.h>
/*
* "conf" is how confident the estimate given by the counter is.
*
* In other words, if the cardinality is estimated to be 100 with 2% error margin and conf is
* In other words, if the cardinality is estimated to be 100 with 2% error margin and HLL_CONFis
* 0.95, then we are 95% sure that the actual cardinality is between 98 and 102.
*/
#define conf .95
#define HLL_CONF .95
class CardinalityVal;
class CardinalityCounter {
friend class CardinalityVal;
@ -114,3 +117,5 @@ class CardinalityCounter {
*/
uint64_t getM();
};
#endif

View file

@ -11,14 +11,16 @@ CardinalityVal::CardinalityVal() : OpaqueVal(new OpaqueType("cardinality"))
CardinalityVal::~CardinalityVal()
{
if ( valid && c )
if ( valid && c != 0 )
delete c;
c = 0;
valid = false;
}
IMPLEMENT_SERIAL(CardinalityVal, SER_CARDINALITY_VAL);
bool CardinalityVal::DoSerialize(SerialInfo* info) const
{
printf("Serializing\n");
DO_SERIALIZE(SER_CARDINALITY_VAL, OpaqueVal);
if ( ! IsValid() )
@ -39,6 +41,7 @@ bool CardinalityVal::DoSerialize(SerialInfo* info) const
bool CardinalityVal::DoUnserialize(UnserialInfo* info)
{
printf("Unserializing\n");
DO_UNSERIALIZE(OpaqueVal);
if ( ! IsValid() )

View file

@ -11,11 +11,11 @@ class CardinalityCounter;
class CardinalityVal: public OpaqueVal {
public:
CardinalityVal();
~CardinalityVal();
bool Init(CardinalityCounter*);
bool IsValid() const { return valid; };
CardinalityCounter* Get() { return c; };
CardinalityVal();
~CardinalityVal();
private:
bool valid;