leerho commented on code in PR #575:
URL: https://github.com/apache/datasketches-cpp/pull/575#discussion_r4623210838


##########
req/include/req_sketch_impl.hpp:
##########
@@ -631,8 +645,27 @@ void req_sketch<T, C, A>::update_num_retained() {
   for (const auto& compactor: compactors_) num_retained_ += 
compactor.get_num_items();
 }
 
+template<typename T, typename C, typename A>
+void req_sketch<T, C, A>::restore_counts() {
+  // the total weight of the retained items is always n
+  n_ = 0;
+  for (const auto& compactor: compactors_) n_ += 
static_cast<uint64_t>(compactor.get_num_items()) << compactor.get_lg_weight();
+  update_num_retained();
+  update_max_nom_size();
+}
+
 template<typename T, typename C, typename A>
 void req_sketch<T, C, A>::compress() {
+  try {
+    compress_levels();
+  } catch (...) {
+    restore_counts(); // a compactor can fail to grow after a compaction moved 
its items

Review Comment:
   Right, same problem as in `merge()`: `compress_levels()` can add a level and 
then fail to compact into it, when the new level fails to allocate space for 
the promoted items. That left the sketch in estimation mode with an empty top 
level.
   
   Fixed in 1267c751: on failure `compress()` now removes the levels it added 
that hold no items, the same way `merge()` does. Both use a new helper, 
`remove_empty_levels_above()`. The allocation tests now also check that a 
sketch in estimation mode retains an item with weight above 1. "failure at each 
allocation of the updates" fails that check without the change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to