mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 23:58:20 +00:00
Remove value serialization.
Note - this compiles, but you cannot run Bro anymore - it crashes immediately with a 0-pointer access. The reason behind it is that the required clone functionality does not work anymore.
This commit is contained in:
parent
9b49c7cbc6
commit
474efe9e69
78 changed files with 58 additions and 9185 deletions
|
@ -5,7 +5,6 @@
|
|||
#include <limits>
|
||||
|
||||
#include "BitVector.h"
|
||||
#include "Serializer.h"
|
||||
#include "digest.h"
|
||||
|
||||
using namespace probabilistic;
|
||||
|
@ -539,56 +538,3 @@ BitVector::size_type BitVector::find_from(size_type i) const
|
|||
return i * bits_per_block + lowest_bit(bits[i]);
|
||||
}
|
||||
|
||||
bool BitVector::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
BitVector* BitVector::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return reinterpret_cast<BitVector*>(SerialObj::Unserialize(info, SER_BITVECTOR));
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(BitVector, SER_BITVECTOR);
|
||||
|
||||
bool BitVector::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BITVECTOR, SerialObj);
|
||||
|
||||
if ( ! SERIALIZE(static_cast<uint64>(bits.size())) )
|
||||
return false;
|
||||
|
||||
for ( size_t i = 0; i < bits.size(); ++i )
|
||||
if ( ! SERIALIZE(static_cast<uint64>(bits[i])) )
|
||||
return false;
|
||||
|
||||
return SERIALIZE(static_cast<uint64>(num_bits));
|
||||
}
|
||||
|
||||
bool BitVector::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
uint64 size;
|
||||
if ( ! UNSERIALIZE(&size) )
|
||||
return false;
|
||||
|
||||
bits.resize(static_cast<size_t>(size));
|
||||
|
||||
for ( size_t i = 0; i < bits.size(); ++i )
|
||||
{
|
||||
uint64 block;
|
||||
if ( ! UNSERIALIZE(&block) )
|
||||
return false;
|
||||
|
||||
bits[i] = static_cast<block_type>(block);
|
||||
}
|
||||
|
||||
uint64 n;
|
||||
if ( ! UNSERIALIZE(&n) )
|
||||
return false;
|
||||
|
||||
num_bits = static_cast<size_type>(n);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -6,16 +6,14 @@
|
|||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
#include "SerialObj.h"
|
||||
|
||||
namespace probabilistic {
|
||||
|
||||
/**
|
||||
* A vector of bits.
|
||||
*/
|
||||
class BitVector : public SerialObj {
|
||||
class BitVector {
|
||||
public:
|
||||
typedef uint64 block_type;
|
||||
typedef uint64_t block_type;
|
||||
typedef size_t size_type;
|
||||
typedef bool const_reference;
|
||||
|
||||
|
@ -281,28 +279,7 @@ public:
|
|||
*
|
||||
* @return The hash.
|
||||
*/
|
||||
uint64 Hash() const;
|
||||
|
||||
/**
|
||||
* Serializes the bit vector.
|
||||
*
|
||||
* @param info The serializaton informationt to use.
|
||||
*
|
||||
* @return True if successful.
|
||||
*/
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
|
||||
/**
|
||||
* Unserialize the bit vector.
|
||||
*
|
||||
* @param info The serializaton informationt to use.
|
||||
*
|
||||
* @return The unserialized bit vector, or null if an error occured.
|
||||
*/
|
||||
static BitVector* Unserialize(UnserialInfo* info);
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(BitVector);
|
||||
uint64_t Hash() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
#include "BloomFilter.h"
|
||||
|
||||
#include "CounterVector.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
#include "../util.h"
|
||||
#include "../Reporter.h"
|
||||
|
||||
using namespace probabilistic;
|
||||
|
||||
|
@ -28,31 +28,6 @@ BloomFilter::~BloomFilter()
|
|||
delete hasher;
|
||||
}
|
||||
|
||||
bool BloomFilter::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
BloomFilter* BloomFilter::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return reinterpret_cast<BloomFilter*>(SerialObj::Unserialize(info, SER_BLOOMFILTER));
|
||||
}
|
||||
|
||||
bool BloomFilter::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BLOOMFILTER, SerialObj);
|
||||
|
||||
return hasher->Serialize(info);
|
||||
}
|
||||
|
||||
bool BloomFilter::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
hasher = Hasher::Unserialize(info);
|
||||
return hasher != 0;
|
||||
}
|
||||
|
||||
size_t BasicBloomFilter::M(double fp, size_t capacity)
|
||||
{
|
||||
double ln2 = std::log(2);
|
||||
|
@ -130,21 +105,6 @@ BasicBloomFilter::~BasicBloomFilter()
|
|||
delete bits;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(BasicBloomFilter, SER_BASICBLOOMFILTER)
|
||||
|
||||
bool BasicBloomFilter::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_BASICBLOOMFILTER, BloomFilter);
|
||||
return bits->Serialize(info);
|
||||
}
|
||||
|
||||
bool BasicBloomFilter::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BloomFilter);
|
||||
bits = BitVector::Unserialize(info);
|
||||
return (bits != 0);
|
||||
}
|
||||
|
||||
void BasicBloomFilter::Add(const HashKey* key)
|
||||
{
|
||||
Hasher::digest_vector h = hasher->Hash(key);
|
||||
|
@ -232,21 +192,6 @@ string CountingBloomFilter::InternalState() const
|
|||
return fmt("%" PRIu64, cells->Hash());
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(CountingBloomFilter, SER_COUNTINGBLOOMFILTER)
|
||||
|
||||
bool CountingBloomFilter::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_COUNTINGBLOOMFILTER, BloomFilter);
|
||||
return cells->Serialize(info);
|
||||
}
|
||||
|
||||
bool CountingBloomFilter::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(BloomFilter);
|
||||
cells = CounterVector::Unserialize(info);
|
||||
return (cells != 0);
|
||||
}
|
||||
|
||||
// TODO: Use partitioning in add/count to allow for reusing CMS bounds.
|
||||
void CountingBloomFilter::Add(const HashKey* key)
|
||||
{
|
||||
|
|
|
@ -14,12 +14,12 @@ class CounterVector;
|
|||
/**
|
||||
* The abstract base class for Bloom filters.
|
||||
*/
|
||||
class BloomFilter : public SerialObj {
|
||||
class BloomFilter {
|
||||
public:
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~BloomFilter() override;
|
||||
virtual ~BloomFilter();
|
||||
|
||||
/**
|
||||
* Adds an element to the Bloom filter.
|
||||
|
@ -71,28 +71,7 @@ public:
|
|||
*/
|
||||
virtual string InternalState() const = 0;
|
||||
|
||||
/**
|
||||
* Serializes the Bloom filter.
|
||||
*
|
||||
* @param info The serializaton information to use.
|
||||
*
|
||||
* @return True if successful.
|
||||
*/
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
|
||||
/**
|
||||
* Unserializes a Bloom filter.
|
||||
*
|
||||
* @param info The serializaton information to use.
|
||||
*
|
||||
* @return The unserialized Bloom filter, or null if an error
|
||||
* occured.
|
||||
*/
|
||||
static BloomFilter* Unserialize(UnserialInfo* info);
|
||||
|
||||
protected:
|
||||
DECLARE_ABSTRACT_SERIAL(BloomFilter);
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
|
@ -165,8 +144,6 @@ public:
|
|||
string InternalState() const override;
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(BasicBloomFilter);
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
|
@ -210,8 +187,6 @@ public:
|
|||
string InternalState() const override;
|
||||
|
||||
protected:
|
||||
DECLARE_SERIAL(CountingBloomFilter);
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "CardinalityCounter.h"
|
||||
#include "Reporter.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
using namespace probabilistic;
|
||||
|
||||
|
@ -197,51 +196,6 @@ uint64_t CardinalityCounter::GetM() const
|
|||
return m;
|
||||
}
|
||||
|
||||
bool CardinalityCounter::Serialize(SerialInfo* info) const
|
||||
{
|
||||
bool valid = true;
|
||||
|
||||
valid &= SERIALIZE(m);
|
||||
valid &= SERIALIZE(V);
|
||||
valid &= SERIALIZE(alpha_m);
|
||||
|
||||
for ( unsigned int i = 0; i < m; i++ )
|
||||
valid &= SERIALIZE((char)buckets[i]);
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
CardinalityCounter* CardinalityCounter::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
uint64_t m;
|
||||
uint64_t V;
|
||||
double alpha_m;
|
||||
|
||||
bool valid = true;
|
||||
valid &= UNSERIALIZE(&m);
|
||||
valid &= UNSERIALIZE(&V);
|
||||
valid &= UNSERIALIZE(&alpha_m);
|
||||
|
||||
CardinalityCounter* c = new CardinalityCounter(m, V, alpha_m);
|
||||
|
||||
vector<uint8_t>& buckets = c->buckets;
|
||||
|
||||
for ( unsigned int i = 0; i < m; i++ )
|
||||
{
|
||||
char c;
|
||||
valid &= UNSERIALIZE(&c);
|
||||
buckets[i] = (uint8_t)c;
|
||||
}
|
||||
|
||||
if ( ! valid )
|
||||
{
|
||||
delete c;
|
||||
c = 0;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* The following function is copied from libc/string/flsll.c from the FreeBSD source
|
||||
* tree. Original copyright message follows
|
||||
|
|
|
@ -84,25 +84,6 @@ public:
|
|||
*/
|
||||
bool Merge(CardinalityCounter* c);
|
||||
|
||||
/**
|
||||
* Serializes the cardinality counter.
|
||||
*
|
||||
* @param info The serializaton information to use.
|
||||
*
|
||||
* @return True if successful.
|
||||
*/
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
|
||||
/**
|
||||
* Unserializes a cardinality counter.
|
||||
*
|
||||
* @param info The serializaton information to use.
|
||||
*
|
||||
* @return The unserialized cardinality counter, or null if an error
|
||||
* occured.
|
||||
*/
|
||||
static CardinalityCounter* Unserialize(UnserialInfo* info);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Return the number of buckets.
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <limits>
|
||||
#include "BitVector.h"
|
||||
#include "Serializer.h"
|
||||
|
||||
using namespace probabilistic;
|
||||
|
||||
|
@ -153,46 +152,8 @@ CounterVector operator|(const CounterVector& x, const CounterVector& y)
|
|||
|
||||
}
|
||||
|
||||
uint64 CounterVector::Hash() const
|
||||
uint64_t CounterVector::Hash() const
|
||||
{
|
||||
return bits->Hash();
|
||||
}
|
||||
|
||||
bool CounterVector::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
CounterVector* CounterVector::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return reinterpret_cast<CounterVector*>(SerialObj::Unserialize(info, SER_COUNTERVECTOR));
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(CounterVector, SER_COUNTERVECTOR)
|
||||
|
||||
bool CounterVector::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_COUNTERVECTOR, SerialObj);
|
||||
|
||||
if ( ! bits->Serialize(info) )
|
||||
return false;
|
||||
|
||||
return SERIALIZE(static_cast<uint64>(width));
|
||||
}
|
||||
|
||||
bool CounterVector::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
bits = BitVector::Unserialize(info);
|
||||
if ( ! bits )
|
||||
return false;
|
||||
|
||||
uint64 w;
|
||||
if ( ! UNSERIALIZE(&w) )
|
||||
return false;
|
||||
|
||||
width = static_cast<size_t>(w);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
#ifndef PROBABILISTIC_COUNTERVECTOR_H
|
||||
#define PROBABILISTIC_COUNTERVECTOR_H
|
||||
|
||||
#include "SerialObj.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace probabilistic {
|
||||
|
||||
|
@ -12,10 +13,10 @@ class BitVector;
|
|||
/**
|
||||
* A vector of counters, each of which has a fixed number of bits.
|
||||
*/
|
||||
class CounterVector : public SerialObj {
|
||||
class CounterVector {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef uint64 count_type;
|
||||
typedef uint64_t count_type;
|
||||
|
||||
/**
|
||||
* Constructs a counter vector having cells of a given width.
|
||||
|
@ -38,7 +39,7 @@ public:
|
|||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~CounterVector() override;
|
||||
virtual ~CounterVector();
|
||||
|
||||
/**
|
||||
* Increments a given cell.
|
||||
|
@ -131,26 +132,7 @@ public:
|
|||
*
|
||||
* @return The hash.
|
||||
*/
|
||||
uint64 Hash() const;
|
||||
|
||||
/**
|
||||
* Serializes the bit vector.
|
||||
*
|
||||
* @param info The serializaton information to use.
|
||||
*
|
||||
* @return True if successful.
|
||||
*/
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
|
||||
/**
|
||||
* Unserialize the counter vector.
|
||||
*
|
||||
* @param info The serializaton information to use.
|
||||
*
|
||||
* @return The unserialized counter vector, or null if an error
|
||||
* occured.
|
||||
*/
|
||||
static CounterVector* Unserialize(UnserialInfo* info);
|
||||
uint64_t Hash() const;
|
||||
|
||||
protected:
|
||||
friend CounterVector operator|(const CounterVector& x,
|
||||
|
@ -158,8 +140,6 @@ protected:
|
|||
|
||||
CounterVector() { }
|
||||
|
||||
DECLARE_SERIAL(CounterVector);
|
||||
|
||||
private:
|
||||
CounterVector& operator=(const CounterVector&); // Disable.
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include "Hasher.h"
|
||||
#include "NetVar.h"
|
||||
#include "Serializer.h"
|
||||
#include "digest.h"
|
||||
#include "siphash24.h"
|
||||
|
||||
|
@ -41,52 +40,6 @@ Hasher::digest_vector Hasher::Hash(const HashKey* key) const
|
|||
return Hash(key->Key(), key->Size());
|
||||
}
|
||||
|
||||
bool Hasher::Serialize(SerialInfo* info) const
|
||||
{
|
||||
return SerialObj::Serialize(info);
|
||||
}
|
||||
|
||||
Hasher* Hasher::Unserialize(UnserialInfo* info)
|
||||
{
|
||||
return reinterpret_cast<Hasher*>(SerialObj::Unserialize(info, SER_HASHER));
|
||||
}
|
||||
|
||||
bool Hasher::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_HASHER, SerialObj);
|
||||
|
||||
if ( ! SERIALIZE(static_cast<uint16>(k)) )
|
||||
return false;
|
||||
|
||||
if ( ! SERIALIZE(static_cast<uint64>(seed.h1)) )
|
||||
return false;
|
||||
|
||||
return SERIALIZE(static_cast<uint64>(seed.h2));
|
||||
}
|
||||
|
||||
bool Hasher::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(SerialObj);
|
||||
|
||||
uint16 serial_k;
|
||||
if ( ! UNSERIALIZE(&serial_k) )
|
||||
return false;
|
||||
|
||||
k = serial_k;
|
||||
assert(k > 0);
|
||||
|
||||
seed_t serial_seed;
|
||||
if ( ! UNSERIALIZE(&serial_seed.h1) )
|
||||
return false;
|
||||
|
||||
if ( ! UNSERIALIZE(&serial_seed.h2) )
|
||||
return false;
|
||||
|
||||
seed = serial_seed;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Hasher::Hasher(size_t arg_k, seed_t arg_seed)
|
||||
{
|
||||
k = arg_k;
|
||||
|
@ -167,31 +120,6 @@ bool DefaultHasher::Equals(const Hasher* other) const
|
|||
return hash_functions == o->hash_functions;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(DefaultHasher, SER_DEFAULTHASHER)
|
||||
|
||||
bool DefaultHasher::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_DEFAULTHASHER, Hasher);
|
||||
|
||||
// Nothing to do here, the base class has all we need serialized already.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DefaultHasher::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Hasher);
|
||||
|
||||
hash_functions.clear();
|
||||
for ( size_t i = 0; i < K(); ++i )
|
||||
{
|
||||
Hasher::seed_t s = Seed();
|
||||
s.h1 += bro_prng(i);
|
||||
hash_functions.push_back(UHF(s));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DoubleHasher::DoubleHasher(size_t k, seed_t seed)
|
||||
: Hasher(k, seed), h1(seed + bro_prng(1)), h2(seed + bro_prng(2))
|
||||
{
|
||||
|
@ -223,22 +151,3 @@ bool DoubleHasher::Equals(const Hasher* other) const
|
|||
return h1 == o->h1 && h2 == o->h2;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIAL(DoubleHasher, SER_DOUBLEHASHER)
|
||||
|
||||
bool DoubleHasher::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_DOUBLEHASHER, Hasher);
|
||||
|
||||
// Nothing to do here, the base class has all we need serialized already.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DoubleHasher::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(Hasher);
|
||||
|
||||
h1 = UHF(Seed() + bro_prng(1));
|
||||
h2 = UHF(Seed() + bro_prng(2));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#define PROBABILISTIC_HASHER_H
|
||||
|
||||
#include "Hash.h"
|
||||
#include "SerialObj.h"
|
||||
|
||||
namespace probabilistic {
|
||||
|
||||
|
@ -12,7 +11,7 @@ namespace probabilistic {
|
|||
* Abstract base class for hashers. A hasher creates a family of hash
|
||||
* functions to hash an element *k* times.
|
||||
*/
|
||||
class Hasher : public SerialObj {
|
||||
class Hasher {
|
||||
public:
|
||||
typedef hash_t digest;
|
||||
typedef std::vector<digest> digest_vector;
|
||||
|
@ -43,7 +42,7 @@ public:
|
|||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Hasher() override { }
|
||||
virtual ~Hasher() { }
|
||||
|
||||
/**
|
||||
* Computes hash values for an element.
|
||||
|
@ -99,12 +98,7 @@ public:
|
|||
*/
|
||||
seed_t Seed() const { return seed; }
|
||||
|
||||
bool Serialize(SerialInfo* info) const;
|
||||
static Hasher* Unserialize(UnserialInfo* info);
|
||||
|
||||
protected:
|
||||
DECLARE_ABSTRACT_SERIAL(Hasher);
|
||||
|
||||
Hasher() { }
|
||||
|
||||
/**
|
||||
|
@ -208,8 +202,6 @@ public:
|
|||
DefaultHasher* Clone() const final;
|
||||
bool Equals(const Hasher* other) const final;
|
||||
|
||||
DECLARE_SERIAL(DefaultHasher);
|
||||
|
||||
private:
|
||||
DefaultHasher() { }
|
||||
|
||||
|
@ -236,8 +228,6 @@ public:
|
|||
DoubleHasher* Clone() const final;
|
||||
bool Equals(const Hasher* other) const final;
|
||||
|
||||
DECLARE_SERIAL(DoubleHasher);
|
||||
|
||||
private:
|
||||
DoubleHasher() { }
|
||||
|
||||
|
|
|
@ -3,13 +3,10 @@
|
|||
#include "probabilistic/Topk.h"
|
||||
#include "CompHash.h"
|
||||
#include "Reporter.h"
|
||||
#include "Serializer.h"
|
||||
#include "NetVar.h"
|
||||
|
||||
namespace probabilistic {
|
||||
|
||||
IMPLEMENT_SERIAL(TopkVal, SER_TOPK_VAL);
|
||||
|
||||
static void topk_element_hash_delete_func(void* val)
|
||||
{
|
||||
Element* e = (Element*) val;
|
||||
|
@ -183,109 +180,6 @@ void TopkVal::Merge(const TopkVal* value, bool doPrune)
|
|||
}
|
||||
}
|
||||
|
||||
bool TopkVal::DoSerialize(SerialInfo* info) const
|
||||
{
|
||||
DO_SERIALIZE(SER_TOPK_VAL, OpaqueVal);
|
||||
|
||||
bool v = true;
|
||||
|
||||
v &= SERIALIZE(size);
|
||||
v &= SERIALIZE(numElements);
|
||||
v &= SERIALIZE(pruned);
|
||||
|
||||
bool type_present = (type != 0);
|
||||
v &= SERIALIZE(type_present);
|
||||
|
||||
if ( type_present )
|
||||
v &= type->Serialize(info);
|
||||
else
|
||||
assert(numElements == 0);
|
||||
|
||||
uint64_t i = 0;
|
||||
std::list<Bucket*>::const_iterator it = buckets.begin();
|
||||
while ( it != buckets.end() )
|
||||
{
|
||||
Bucket* b = *it;
|
||||
uint32_t elements_count = b->elements.size();
|
||||
v &= SERIALIZE(elements_count);
|
||||
v &= SERIALIZE(b->count);
|
||||
|
||||
std::list<Element*>::const_iterator eit = b->elements.begin();
|
||||
while ( eit != b->elements.end() )
|
||||
{
|
||||
Element* element = *eit;
|
||||
v &= SERIALIZE(element->epsilon);
|
||||
v &= element->value->Serialize(info);
|
||||
|
||||
eit++;
|
||||
i++;
|
||||
}
|
||||
|
||||
it++;
|
||||
}
|
||||
|
||||
assert(i == numElements);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
bool TopkVal::DoUnserialize(UnserialInfo* info)
|
||||
{
|
||||
DO_UNSERIALIZE(OpaqueVal);
|
||||
|
||||
bool v = true;
|
||||
|
||||
v &= UNSERIALIZE(&size);
|
||||
v &= UNSERIALIZE(&numElements);
|
||||
v &= UNSERIALIZE(&pruned);
|
||||
|
||||
bool type_present = false;
|
||||
v &= UNSERIALIZE(&type_present);
|
||||
if ( type_present )
|
||||
{
|
||||
BroType* deserialized_type = BroType::Unserialize(info);
|
||||
|
||||
Typify(deserialized_type);
|
||||
Unref(deserialized_type);
|
||||
assert(type);
|
||||
}
|
||||
else
|
||||
assert(numElements == 0);
|
||||
|
||||
uint64_t i = 0;
|
||||
while ( i < numElements )
|
||||
{
|
||||
Bucket* b = new Bucket();
|
||||
uint32_t elements_count;
|
||||
v &= UNSERIALIZE(&elements_count);
|
||||
v &= UNSERIALIZE(&b->count);
|
||||
b->bucketPos = buckets.insert(buckets.end(), b);
|
||||
|
||||
for ( uint64_t j = 0; j < elements_count; j++ )
|
||||
{
|
||||
Element* e = new Element();
|
||||
v &= UNSERIALIZE(&e->epsilon);
|
||||
e->value = Val::Unserialize(info, type);
|
||||
e->parent = b;
|
||||
|
||||
b->elements.insert(b->elements.end(), e);
|
||||
|
||||
HashKey* key = GetHash(e->value);
|
||||
assert (elementDict->Lookup(key) == 0);
|
||||
|
||||
elementDict->Insert(key, e);
|
||||
delete key;
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
assert(i == numElements);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
VectorVal* TopkVal::GetTopK(int k) const // returns vector
|
||||
{
|
||||
if ( numElements == 0 )
|
||||
|
|
|
@ -161,8 +161,6 @@ private:
|
|||
uint64 size; // how many elements are we tracking?
|
||||
uint64 numElements; // how many elements do we have at the moment
|
||||
bool pruned; // was this data structure pruned?
|
||||
|
||||
DECLARE_SERIAL(TopkVal);
|
||||
};
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue