Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/fi_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, W, H, E>::is_empty,
"Returns True if the sketch is empty, otherwise False")
.def("reset", &frequent_items_sketch<T, W, H, E>::reset,
"Resets the sketch to the initial empty state")
.def_prop_ro("num_active_items", &frequent_items_sketch<T, W, H, E>::get_num_active_items,
"The number of active items in the sketch")
.def_prop_ro("total_weight", &frequent_items_sketch<T, W, H, E>::get_total_weight,
Expand Down
4 changes: 2 additions & 2 deletions src/hll_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions src/theta_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
;
Expand Down
7 changes: 7 additions & 0 deletions tests/fi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 6 additions & 0 deletions tests/hll_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/theta_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading