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


##########
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:
   In here we should also reset compactors. Because `compress_levels` call 
`grow`



-- 
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