in src/fi_wrapper.cpp [142:165]
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, py_object_serde& serde) { return sk.get_serialized_size_bytes(serde); },
nb::arg("serde"),
"Computes the size needed to serialize the current state of the sketch using the provided serde. This can be expensive since every item needs to be looked at."
)
.def(
"serialize",
[](const frequent_items_sketch<T, W, H, E>& sk, py_object_serde& serde) {
auto bytes = sk.serialize(0, serde);
return nb::bytes(reinterpret_cast<const char*>(bytes.data()), bytes.size());
}, nb::arg("serde"),
"Serializes the sketch into a bytes object using the provided serde."
)
.def_static(
"deserialize",
[](const nb::bytes& bytes, py_object_serde& serde) {
return frequent_items_sketch<T, W, H, E>::deserialize(bytes.c_str(), bytes.size(), serde);
}, nb::arg("bytes"), nb::arg("serde"),
"Reads a bytes object using the provided serde and returns the corresponding frequent_strings_sketch."
);
}