tisonkun opened a new pull request, #359:
URL: https://github.com/apache/datasketches-rust/pull/359
## Summary
Rewrite `datasketches::bloom` around a dedicated `BitArray` storage/probe
module (`datasketches/src/bloom/bit_array.rs`) and direct fallible constructors
on `BloomFilter` (`datasketches/src/bloom/filter.rs`), removing
`BloomFilterBuilder` and the monolithic `datasketches/src/bloom/sketch.rs`.
## Changes
- **Direct constructors instead of `BloomFilterBuilder`**: Remove
`BloomFilterBuilder` and expose `BloomFilter::with_accuracy`,
`BloomFilter::with_accuracy_and_seed`, `BloomFilter::with_size`, and
`BloomFilter::with_size_and_seed`, validating `max_items`, `fpp`, `num_bits`,
and `num_hashes` eagerly at construction and returning `Result<BloomFilter,
Error>`.
- **Consistent `u64` capacity and 32-bit double hashing**: Change
`BloomFilter::capacity` from `usize` to `u64` and compute double-hashing probe
slots (`(h0.wrapping_add(u64::from(i).wrapping_mul(h1))) >> 1`) and
Granlund-Montgomery fast remainder reduction in full `u64` arithmetic instead
of truncating via `as usize` before shifting, aligning 32-bit (`wasm32`) bit
layouts with 64-bit targets, Java, C++, and Go.
- **Modular `BitArray` encapsulation and bounded deserialization**: Move
word-backed storage, Granlund-Montgomery multiplier/shift state (deriving bit
capacity from `words.len()` instead of storing a redundant `capacity` field),
shared `combine`-based `union`/`intersect`/`difference` passes, and hot probe
loops (`#[inline(always)]` alongside `#[inline(always)]` on
`BloomFilter::hash_pair`) into `BitArray`; validate `num_longs` against
`1..=MAX_WORDS`, `MAX_ALLOCATABLE_WORDS`, and remaining payload length before
allocating non-empty images.
- **Tests, benchmarks, example, and changelog**: Consolidate behavior tests
into `tests-integration/tests/bloom_test/filter.rs` (including cross-language
serialized bit-layout verification), add invalid `num_longs` deserialization
coverage in `tests-integration/tests/serde_tests/bloom.rs`, add `bloom::query`
benchmarks in `benchmarks/bloom/query.rs`, update
`datasketches/examples/bloom_difference.rs`, and document the breaking changes
in `CHANGELOG.md`.
## Validation
- `cargo update -w --locked --verbose`: passed.
- `cargo x lint`: passed (nightly `clippy` with `-D warnings`, `rustfmt
--check`, `docsrs` rustdoc with `-D warnings`, `taplo format --check`, `typos`,
and `hawkeye check` across 228 files).
- `cargo x check`: passed across `--no-default-features`, each individual
feature, and all features with `RUSTFLAGS="-Dwarnings"`.
- `cargo x test`: passed (738 passed, 0 failed, 0 ignored across workspace
unit tests, integration tests including `bloom_test` and `serde_tests`, and 133
doctests).
- `cargo +1.86.0 x test`: passed (738 passed, 0 failed, 0 ignored on MSRV
1.86.0).
- `cargo check -p datasketches --target wasm32-unknown-unknown
--all-features`: passed.
- `cargo x bench -- --test`: passed (321/321 benchmark smoke cases ok).
- `cargo run -p datasketches --example bloom_difference --features bloom`:
passed (`96928 / 99500 valid objects (97.4% retained; drops become cache
misses)`, `Shipped filter: 119848 bytes`).
## Benchmarks
Three alternating rounds (`--repeat 10` per round) comparing `main` against
this branch:
| Benchmark | Rounds | R1 (main ->
PR) | R2 (PR -> main) | R3 (main -> PR)
| Median (main -> PR) |
| ------------------------------------------------ | ------ |
------------------------------- | ------------------------------- |
------------------------------- | ------------------- |
| `bloom::update::u64` | 2,000 | 234 (228..246)
/ 229 (226..238) | 236 (230..245) / 233 (233..235) | 239 (234..245) / 237
(236..242) | 234 -> 236 (+0.9%) |
| `bloom::update::bytes_32` | 1,000 | 223 (218..229)
/ 216 (214..219) | 220 (218..224) / 226 (222..236) | 230 (225..243) / 231
(224..254) | 226 -> 220 (-2.7%) |
| `bloom::update::contains_and_insert_present_u64` | 2,000 | 185 (181..191)
/ 178 (175..183) | 181 (180..183) / 186 (184..188) | 194 (190..213) / 187
(185..197) | 186 -> 181 (-2.7%) |
Baseline measurements (`--repeat 10` per round) for the new `bloom::query`
benchmarks on this branch:
| Benchmark | Rounds | R1 ms | R2 ms
| R3 ms | Median ms |
| -------------------------------- | ------ | -------------- |
-------------- | -------------- | --------- |
| `bloom::query::present_u64` | 2,000 | 215 (210..237) | 222
(217..227) | 225 (218..231) | 222 |
| `bloom::query::absent_u64` | 2,000 | 89 (87..113) | 92 (89..96)
| 92 (89..99) | 92 |
| `bloom::query::present_bytes_32` | 1,000 | 214 (211..220) | 214
(212..219) | 226 (222..233) | 214 |
| `bloom::query::absent_bytes_32` | 1,000 | 167 (158..193) | 162
(153..185) | 191 (173..204) | 167 |
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]