Visitar URL original
add additional methods to bloom wrapper · apache/datasketches-python@ae2e5b3 · GitHub
Skip to content

Commit ae2e5b3

Browse files
author
Jon
committed
add additional methods to bloom wrapper
1 parent 77ca90c commit ae2e5b3

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

‎src/bloom_wrapper.cpp‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ void init_bloom(nb::module_ &m) {
5656
nb::arg("target_false_positive_prob"),
5757
nb::arg("seed") = nb::none()
5858
)
59+
.def_static("initalize_by_accuracy",
60+
[](nb::bytearray& bytearray, uint64_t max_distinct_items, double target_fpp, std::optional<uint64_t> seed) {
61+
return bloom_filter::builder::initialize_by_accuracy(
62+
PyByteArray_AsString(bytearray.ptr()),
63+
bytearray.size(),
64+
max_distinct_items,
65+
target_fpp,
66+
seed.value_or(bloom_filter::builder::generate_random_seed()));
67+
},
68+
nb::arg("memory"),
69+
nb::arg("max_distinct_items"),
70+
nb::arg("target_false_positive_prob"),
71+
nb::arg("seed") = nb::none()
72+
)
5973
.def_static("create_by_size",
6074
[](uint64_t num_bits, uint16_t num_hashes, std::optional<uint64_t> seed) {
6175
return bloom_filter::builder::create_by_size(num_bits,
@@ -66,6 +80,20 @@ void init_bloom(nb::module_ &m) {
6680
nb::arg("num_hashes"),
6781
nb::arg("seed") = nb::none()
6882
)
83+
.def_static("initialize_by_size",
84+
[](nb::bytearray& bytearray, uint64_t num_bits, uint16_t num_hashes, std::optional<uint64_t> seed) {
85+
return bloom_filter::builder::initialize_by_size(
86+
PyByteArray_AsString(bytearray.ptr()),
87+
bytearray.size(),
88+
num_bits,
89+
num_hashes,
90+
seed.value_or(bloom_filter::builder::generate_random_seed()));
91+
},
92+
nb::arg("memory"),
93+
nb::arg("num_bits"),
94+
nb::arg("num_hashes"),
95+
nb::arg("seed") = nb::none()
96+
)
6997

7098

7199
.def_static("deserialize",
@@ -81,7 +109,7 @@ void init_bloom(nb::module_ &m) {
81109
)
82110
.def_static(
83111
"writable_wrap",
84-
[](const nb::bytearray& bytearray) {
112+
[](nb::bytearray& bytearray) {
85113
return bloom_filter::writable_wrap(const_cast<char*>(bytearray.c_str()), bytearray.size());
86114
},
87115
nb::arg("bytearray"),
@@ -150,7 +178,16 @@ void init_bloom(nb::module_ &m) {
150178
"Returns the hash seed for this Bloom filter")
151179
.def("reset", &bloom_filter::reset,
152180
"Returns the Bloom filter to its original empty state")
153-
181+
.def("is_read_only", &bloom_filter::is_read_only,
182+
"Returns True if the Bloom filter is read-only, otherwise False")
183+
.def("is_memory_owned", &bloom_filter::is_memory_owned,
184+
"Returns True if the Bloom filter owns the backing array, otherwise False")
185+
.def("is_wrapped", &bloom_filter::is_wrapped,
186+
"Returns True if the Bloom filter was created by wrapping memory\n"
187+
"whether writable or not, otherwise False")
188+
.def("is_compatible", &bloom_filter::is_compatible,
189+
nb::arg("other"),
190+
"Returns True iff the two Bloom filters may be unioned or intersected")
154191
.def("get_serialized_size_bytes", [](const bloom_filter& bf) { return bf.get_serialized_size_bytes(); },
155192
"Returns the number of bytes needed to serialize the Bloom filter")
156193
.def_static("get_serialized_size_bytes_given_bits", [](uint64_t num_bits) { return bloom_filter::get_serialized_size_bytes(num_bits); },

0 commit comments

Comments
 (0)