diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e74346b..35921d1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,7 +117,7 @@ cmake_policy(SET CMP0097 NEW) include(ExternalProject) ExternalProject_Add(datasketches GIT_REPOSITORY https://github.com/apache/datasketches-cpp.git - GIT_TAG 5.2.0 + GIT_TAG 5.3.0 GIT_SHALLOW true GIT_SUBMODULES "" INSTALL_DIR /tmp/datasketches diff --git a/src/fi_wrapper.cpp b/src/fi_wrapper.cpp index c14debaf..0fffcc16 100644 --- a/src/fi_wrapper.cpp +++ b/src/fi_wrapper.cpp @@ -62,6 +62,8 @@ void bind_fi_sketch(nb::module_ &m, const char* name) { "Merges the given sketch into this one") .def("is_empty", &frequent_items_sketch::is_empty, "Returns True if the sketch is empty, otherwise False") + .def("reset", &frequent_items_sketch::reset, + "Resets the sketch to the initial empty state") .def_prop_ro("num_active_items", &frequent_items_sketch::get_num_active_items, "The number of active items in the sketch") .def_prop_ro("total_weight", &frequent_items_sketch::get_total_weight, diff --git a/src/hll_wrapper.cpp b/src/hll_wrapper.cpp index 51041ad3..a3adf4f6 100644 --- a/src/hll_wrapper.cpp +++ b/src/hll_wrapper.cpp @@ -65,8 +65,8 @@ void init_hll(nb::module_ &m) { "Returns the size of the serialized sketch") .def("get_compact_serialization_bytes", &hll_sketch::get_compact_serialization_bytes, "Returns the size of the serialized sketch when compressing the exception table if HLL_4") - .def("reset", &hll_sketch::reset, - "Resets the sketch to the empty state in coupon collection mode") + .def("reset", &hll_sketch::reset, nb::arg("full_size")=false, + "Resets the sketch to the empty state, in coupon collection mode or, if full_size is True, as a full-size HLL array") .def("update", (void (hll_sketch::*)(int64_t)) &hll_sketch::update, nb::arg("datum"), "Updates the sketch with the given integral value") .def("update", (void (hll_sketch::*)(double)) &hll_sketch::update, nb::arg("datum"), diff --git a/src/theta_wrapper.cpp b/src/theta_wrapper.cpp index 2915e175..3e1d3b19 100644 --- a/src/theta_wrapper.cpp +++ b/src/theta_wrapper.cpp @@ -88,8 +88,8 @@ void init_theta(nb::module_ &m) { "Updates the sketch with the given floating point value") .def("update", (void (update_theta_sketch::*)(const std::string&)) &update_theta_sketch::update, nb::arg("datum"), "Updates the sketch with the given string") - .def("compact", &update_theta_sketch::compact, nb::arg("ordered")=true, - "Returns a compacted form of the sketch, optionally sorting it") + .def("compact", &update_theta_sketch::compact, nb::arg("ordered")=true, nb::arg("trim")=false, + "Returns a compacted form of the sketch, optionally sorting it and trimming it to at most the nominal size k") .def("trim", &update_theta_sketch::trim, "Removes retained entries in excess of the nominal size k (if any)") .def("reset", &update_theta_sketch::reset, "Resets the sketch to the initial empty state") ; diff --git a/tests/fi_test.py b/tests/fi_test.py index 6d56aff6..88e65acc 100644 --- a/tests/fi_test.py +++ b/tests/fi_test.py @@ -148,5 +148,12 @@ def test_fi_sketch(self): reference_apriori_error = frequent_strings_sketch.get_apriori_error(k, wt) self.assertAlmostEqual(sk_apriori_error, reference_apriori_error, delta=1e-6) + fi.update("a", 5) + self.assertFalse(fi.is_empty()) + fi.reset() + self.assertTrue(fi.is_empty()) + self.assertEqual(fi.total_weight, 0) + self.assertEqual(fi.num_active_items, 0) + if __name__ == '__main__': unittest.main() diff --git a/tests/hll_test.py b/tests/hll_test.py index fba7727b..c00816c5 100644 --- a/tests/hll_test.py +++ b/tests/hll_test.py @@ -101,6 +101,12 @@ def test_hll_sketch(self): hll.reset() self.assertTrue(hll.is_empty()) + # reset can also return to an empty full-size HLL array + hll.reset(full_size=True) + self.assertTrue(hll.is_empty()) + full = hll_sketch(lgk, tgt_hll_type.HLL_6, True) + self.assertEqual(hll.get_updatable_serialization_bytes(), full.get_updatable_serialization_bytes()) + def test_hll_union(self): lgk = 7 n = 53 diff --git a/tests/theta_test.py b/tests/theta_test.py index 1d2da0f7..c418ae21 100644 --- a/tests/theta_test.py +++ b/tests/theta_test.py @@ -68,6 +68,11 @@ def test_theta_basic_example(self): count = count + 1 self.assertEqual(count, new_sk.num_retained) + # compact can also trim the result to at most k entries + trimmed = sk.compact(trim=True) + self.assertLessEqual(trimmed.num_retained, 1 << lgk) + self.assertLessEqual(trimmed.num_retained, sk.num_retained) + num = sk.num_retained sk.trim() self.assertLessEqual(sk.num_retained, num)