Skip to content
Permalink
Browse files
add sanity check on item counts in deserialization constructor
  • Loading branch information
jmalkin committed May 6, 2022
1 parent 5008526 commit 7bac0474a812e0bb4c7e8723f48f3ae2238b4f17
Showing 1 changed file with 8 additions and 2 deletions.
@@ -129,7 +129,14 @@ levels_(std::move(levels)),
min_value_(min_value.release()),
max_value_(max_value.release()),
is_sorted_(is_sorted)
{}
{
uint32_t item_count = base_buffer_.size();
for (Level& lvl : levels_) {
item_count += lvl.size();
}
if (item_count != compute_retained_items(k_, n_))
throw std::logic_error("Item count does not match value computed from k, n");
}

template<typename T, typename C, typename A>
quantiles_sketch<T, C, A>::~quantiles_sketch() {
@@ -371,7 +378,6 @@ auto quantiles_sketch<T, C, A>::deserialize(std::istream &is, const SerDe& serde
if (levels_needed > 0) {
uint64_t working_pattern = bit_pattern;
for (size_t i = 0; i < levels_needed; ++i, working_pattern >>= 1) {

if ((working_pattern & 0x01) == 1) {
Level level = deserialize_array(is, k, k, serde, allocator);
levels.push_back(std::move(level));

0 comments on commit 7bac047

Please sign in to comment.