mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
persistence really works.
It took me way too long to find this - I got the uint8 serialize/deserialize wrong :/
This commit is contained in:
parent
70c020e412
commit
8340af55d1
5 changed files with 50 additions and 9 deletions
|
@ -43,7 +43,7 @@ CardinalityCounter::CardinalityCounter(uint64_t size)
|
||||||
V = m;
|
V = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardinalityCounter :: CardinalityCounter(double error_margin)
|
CardinalityCounter::CardinalityCounter(double error_margin)
|
||||||
{
|
{
|
||||||
int b = optimalB(error_margin);
|
int b = optimalB(error_margin);
|
||||||
m = (uint64_t) pow(2, b);
|
m = (uint64_t) pow(2, b);
|
||||||
|
@ -101,9 +101,9 @@ void CardinalityCounter::addElement(uint64_t hash)
|
||||||
double CardinalityCounter::size()
|
double CardinalityCounter::size()
|
||||||
{
|
{
|
||||||
double answer = 0;
|
double answer = 0;
|
||||||
for (int i = 0; i < m; i++)
|
for (int i = 0; i < m; i++)
|
||||||
answer += pow(2, -(int)buckets[i]);
|
answer += pow(2, -(int)buckets[i]);
|
||||||
|
|
||||||
answer = 1/answer;
|
answer = 1/answer;
|
||||||
answer = alpha_m*m*m*answer;
|
answer = alpha_m*m*m*answer;
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,7 @@ bool CardinalityVal::DoSerialize(SerialInfo* info) const
|
||||||
serialvalid &= SERIALIZE(c->V);
|
serialvalid &= SERIALIZE(c->V);
|
||||||
serialvalid &= SERIALIZE(c->alpha_m);
|
serialvalid &= SERIALIZE(c->alpha_m);
|
||||||
for ( int i = 0; i < c->m; i++ )
|
for ( int i = 0; i < c->m; i++ )
|
||||||
{
|
serialvalid &= SERIALIZE( c->buckets[i] );
|
||||||
serialvalid &= SERIALIZE(c->buckets[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return serialvalid;
|
return serialvalid;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +61,6 @@ bool CardinalityVal::DoUnserialize(UnserialInfo* info)
|
||||||
uint8_t* currbucket = buckets + i;
|
uint8_t* currbucket = buckets + i;
|
||||||
serialvalid &= UNSERIALIZE( currbucket );
|
serialvalid &= UNSERIALIZE( currbucket );
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,6 @@ bool BinarySerializationFormat::Read(uint8* v, const char* tag)
|
||||||
if ( ! ReadData(v, sizeof(*v)) )
|
if ( ! ReadData(v, sizeof(*v)) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*v = ntohs(*v);
|
|
||||||
DBG_LOG(DBG_SERIAL, "Read uint8 %hu [%s]", *v, tag);
|
DBG_LOG(DBG_SERIAL, "Read uint8 %hu [%s]", *v, tag);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +313,6 @@ bool BinarySerializationFormat::Write(char v, const char* tag)
|
||||||
bool BinarySerializationFormat::Write(uint8 v, const char* tag)
|
bool BinarySerializationFormat::Write(uint8 v, const char* tag)
|
||||||
{
|
{
|
||||||
DBG_LOG(DBG_SERIAL, "Write uint8 %hu [%s]", v, tag);
|
DBG_LOG(DBG_SERIAL, "Write uint8 %hu [%s]", v, tag);
|
||||||
v = htons(v);
|
|
||||||
return WriteData(&v, sizeof(v));
|
return WriteData(&v, sizeof(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
testing/btest/Baseline/bifs.hll_persistence/out
Normal file
6
testing/btest/Baseline/bifs.hll_persistence/out
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
1
|
||||||
|
10.000763
|
||||||
|
2
|
||||||
|
10.000763
|
||||||
|
3
|
||||||
|
11.000923
|
40
testing/btest/bifs/hll_persistence.bro
Normal file
40
testing/btest/bifs/hll_persistence.bro
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# @TEST-EXEC: bro -b %INPUT runnumber=1 >out
|
||||||
|
# @TEST-EXEC: bro -b %INPUT runnumber=2 >>out
|
||||||
|
# @TEST-EXEC: bro -b %INPUT runnumber=3 >>out
|
||||||
|
# @TEST-EXEC: btest-diff out
|
||||||
|
|
||||||
|
global runnumber: count &redef; # differentiate first and second run
|
||||||
|
|
||||||
|
global card: opaque of cardinality &persistent;
|
||||||
|
|
||||||
|
event bro_init()
|
||||||
|
{
|
||||||
|
print runnumber;
|
||||||
|
|
||||||
|
if ( runnumber == 1 )
|
||||||
|
{
|
||||||
|
card = hll_cardinality_init(0.01);
|
||||||
|
|
||||||
|
hll_cardinality_add(card, "a");
|
||||||
|
hll_cardinality_add(card, "b");
|
||||||
|
hll_cardinality_add(card, "c");
|
||||||
|
hll_cardinality_add(card, "d");
|
||||||
|
hll_cardinality_add(card, "e");
|
||||||
|
hll_cardinality_add(card, "f");
|
||||||
|
hll_cardinality_add(card, "g");
|
||||||
|
hll_cardinality_add(card, "h");
|
||||||
|
hll_cardinality_add(card, "i");
|
||||||
|
hll_cardinality_add(card, "j");
|
||||||
|
}
|
||||||
|
|
||||||
|
print hll_cardinality_estimate(card);
|
||||||
|
|
||||||
|
if ( runnumber == 2 )
|
||||||
|
{
|
||||||
|
hll_cardinality_add(card, "a");
|
||||||
|
hll_cardinality_add(card, "b");
|
||||||
|
hll_cardinality_add(card, "c");
|
||||||
|
hll_cardinality_add(card, "aa");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue