in src/fi_wrapper.cpp [117:138]
void add_serialization(nb::class_<datasketches::frequent_items_sketch<T, W, H, E>>& clazz) {
using namespace datasketches;
clazz.def(
"get_serialized_size_bytes",
[](const frequent_items_sketch<T, W, H, E>& sk) { return sk.get_serialized_size_bytes(); },
"Computes the size needed to serialize the current state of the sketch. This can be expensive since every item needs to be looked at."
)
.def(
"serialize",
[](const frequent_items_sketch<T, W, H, E>& sk) {
auto bytes = sk.serialize();
return nb::bytes(reinterpret_cast<const char*>(bytes.data()), bytes.size());
},
"Serializes the sketch into a bytes object."
)
.def_static(
"deserialize",
[](const nb::bytes& bytes) { return frequent_items_sketch<T, W, H, E>::deserialize(bytes.c_str(), bytes.size()); },
nb::arg("bytes"),
"Reads a bytes object and returns the corresponding frequent_strings_sketch."
);
}