This is an automated email from the ASF dual-hosted git repository.
jmalkin pushed a commit to branch bloom
in repository https://gitbox.apache.org/repos/asf/datasketches-python.git
The following commit(s) were added to refs/heads/bloom by this push:
new ae2e5b3 add additional methods to bloom wrapper
ae2e5b3 is described below
commit ae2e5b359b455b30063e5cae518527de0c4bcaf6
Author: Jon <[email protected]>
AuthorDate: Tue Oct 22 11:36:02 2024 -0700
add additional methods to bloom wrapper
---
src/bloom_wrapper.cpp | 41 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 39 insertions(+), 2 deletions(-)
diff --git a/src/bloom_wrapper.cpp b/src/bloom_wrapper.cpp
index c40c472..0c23bbd 100644
--- a/src/bloom_wrapper.cpp
+++ b/src/bloom_wrapper.cpp
@@ -56,6 +56,20 @@ void init_bloom(nb::module_ &m) {
nb::arg("target_false_positive_prob"),
nb::arg("seed") = nb::none()
)
+ .def_static("initalize_by_accuracy",
+ [](nb::bytearray& bytearray, uint64_t max_distinct_items, double
target_fpp, std::optional<uint64_t> seed) {
+ return bloom_filter::builder::initialize_by_accuracy(
+ PyByteArray_AsString(bytearray.ptr()),
+ bytearray.size(),
+ max_distinct_items,
+ target_fpp,
+ seed.value_or(bloom_filter::builder::generate_random_seed()));
+ },
+ nb::arg("memory"),
+ nb::arg("max_distinct_items"),
+ nb::arg("target_false_positive_prob"),
+ nb::arg("seed") = nb::none()
+ )
.def_static("create_by_size",
[](uint64_t num_bits, uint16_t num_hashes, std::optional<uint64_t>
seed) {
return bloom_filter::builder::create_by_size(num_bits,
@@ -66,6 +80,20 @@ void init_bloom(nb::module_ &m) {
nb::arg("num_hashes"),
nb::arg("seed") = nb::none()
)
+ .def_static("initialize_by_size",
+ [](nb::bytearray& bytearray, uint64_t num_bits, uint16_t num_hashes,
std::optional<uint64_t> seed) {
+ return bloom_filter::builder::initialize_by_size(
+ PyByteArray_AsString(bytearray.ptr()),
+ bytearray.size(),
+ num_bits,
+ num_hashes,
+ seed.value_or(bloom_filter::builder::generate_random_seed()));
+ },
+ nb::arg("memory"),
+ nb::arg("num_bits"),
+ nb::arg("num_hashes"),
+ nb::arg("seed") = nb::none()
+ )
.def_static("deserialize",
@@ -81,7 +109,7 @@ void init_bloom(nb::module_ &m) {
)
.def_static(
"writable_wrap",
- [](const nb::bytearray& bytearray) {
+ [](nb::bytearray& bytearray) {
return
bloom_filter::writable_wrap(const_cast<char*>(bytearray.c_str()),
bytearray.size());
},
nb::arg("bytearray"),
@@ -150,7 +178,16 @@ void init_bloom(nb::module_ &m) {
"Returns the hash seed for this Bloom filter")
.def("reset", &bloom_filter::reset,
"Returns the Bloom filter to its original empty state")
-
+ .def("is_read_only", &bloom_filter::is_read_only,
+ "Returns True if the Bloom filter is read-only, otherwise False")
+ .def("is_memory_owned", &bloom_filter::is_memory_owned,
+ "Returns True if the Bloom filter owns the backing array, otherwise
False")
+ .def("is_wrapped", &bloom_filter::is_wrapped,
+ "Returns True if the Bloom filter was created by wrapping memory\n"
+ "whether writable or not, otherwise False")
+ .def("is_compatible", &bloom_filter::is_compatible,
+ nb::arg("other"),
+ "Returns True iff the two Bloom filters may be unioned or
intersected")
.def("get_serialized_size_bytes", [](const bloom_filter& bf) { return
bf.get_serialized_size_bytes(); },
"Returns the number of bytes needed to serialize the Bloom filter")
.def_static("get_serialized_size_bytes_given_bits", [](uint64_t num_bits)
{ return bloom_filter::get_serialized_size_bytes(num_bits); },
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]