mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 23:58:20 +00:00
Fix cardinalitycounter deserialization.
This one took me way too long to admit. Values were pushed back on deserialization - instead of assigned. Meaning they were added to the end of the already 0-assigned vector. The mean thing here is that estimation still worked - just merging resulted in 0. And estimation still was correct because m, V, alpha_m are enough for this - and those were correctly copied... With this change, all tests pass.
This commit is contained in:
parent
618f0802f4
commit
ca28b98fd4
6 changed files with 19 additions and 6 deletions
|
@ -201,10 +201,10 @@ broker::expected<broker::data> CardinalityCounter::Serialize() const
|
|||
broker::vector v = {m, V, alpha_m};
|
||||
v.reserve(3 + m);
|
||||
|
||||
for ( size_t i = 0; i < m; ++i )
|
||||
for ( size_t i = 0; i < m; ++i )
|
||||
v.emplace_back(static_cast<uint64>(buckets[i]));
|
||||
|
||||
return {v};
|
||||
return {v};
|
||||
}
|
||||
|
||||
std::unique_ptr<CardinalityCounter> CardinalityCounter::Unserialize(const broker::data& data)
|
||||
|
@ -219,19 +219,22 @@ std::unique_ptr<CardinalityCounter> CardinalityCounter::Unserialize(const broker
|
|||
|
||||
if ( ! (m && V && alpha_m) )
|
||||
return nullptr;
|
||||
|
||||
if ( v->size() != 3 + *m )
|
||||
return nullptr;
|
||||
|
||||
auto cc = std::unique_ptr<CardinalityCounter>(new CardinalityCounter(*m, *V, *alpha_m));
|
||||
if ( *m != cc->m )
|
||||
return nullptr;
|
||||
if ( cc->buckets.size() != * m )
|
||||
return nullptr;
|
||||
|
||||
for ( size_t i = 0; i < *m; ++i )
|
||||
for ( size_t i = 0; i < *m; ++i )
|
||||
{
|
||||
auto x = caf::get_if<uint64>(&(*v)[3 + i]);
|
||||
if ( ! x )
|
||||
return nullptr;
|
||||
|
||||
cc->buckets.push_back(*x);
|
||||
cc->buckets[i] = *x;
|
||||
}
|
||||
|
||||
return cc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue