tisonkun opened a new pull request, #360:
URL: https://github.com/apache/datasketches-rust/pull/360

   ## Summary
   
   Accuracy-based Bloom filter construction can undersize the bit array because 
the continuous sizing formula does not account for the final integer hash 
count. For 10,000 items, a 90% target previously selected 2,240 bits and one 
hash, producing about 98.7% false positives in a deterministic integer 
workload. A 50% target selected two hashes after rounding the bit count, 
producing about 55.7% false positives.
   
   Choose `k = max(1, ceil(-ln(p) / ln(2)))`, then solve `m = ceil(-k*n / ln(1 
- p^(1/k)))` before word alignment. The same workloads now produce about 90.2% 
and 49.6% false positives, respectively. Sizing uses the standard probability 
model rather than promising a hard bound on every input distribution.
   
   
[Java](https://github.com/apache/datasketches-java/blob/main/src/main/java/org/apache/datasketches/filters/bloomfilter/BloomFilterBuilder.java)
 and 
[Go](https://github.com/apache/datasketches-go/blob/main/filters/bloom_filter_builder.go)
 also derive the hash count from the rounded bit count. 
[C++](https://github.com/apache/datasketches-cpp/blob/master/filters/include/bloom_filter_builder_impl.hpp)
 derives it directly from the target probability, but still uses the continuous 
bit-count formula. This change uses the direct hash-count calculation and sizes 
the array for that integer count.
   
   **Compatibility:** `with_accuracy` can now choose a different capacity or 
hash count. To combine new filters with an existing filter, use 
`with_size(existing.capacity(), existing.num_hashes())` and the same seed. This 
also applies when sharing configurations across languages.
   
   ## Membership updates and regression coverage
   
   `contains_and_insert` now reads probes until the first missing bit, then 
resumes the existing branchless insertion loop with the remaining probes. It 
retains a read-only path for existing items and avoids maintaining a second 
update loop. Add absent, mixed, and initially empty workloads alongside the 
existing all-present benchmark.
   
   Keep regression coverage small: one sizing test checks the modeled 
probability at representative and extreme targets; one private test compares 
fast reduction with `%` at quotient boundaries, including the maximum supported 
capacity without allocating its bit array; the existing deserialization length 
test also rejects a truncated payload. Existing update-equivalence and 
collision tests exercise the revised insertion path.
   
   ## Performance
   
   Apple M4 Max, aarch64 macOS, rustc 1.101.0-nightly (`8006091eb`, LLVM 
23.1.4), default release optimization. Both revisions use the same 10,000-item 
benchmark definitions and the corrected 1% sizing. Compare `6d81901` with 
`b37ddfb`, using the benchmark additions on both sides. Seven paired runs 
alternate baseline/head order, each invoking the benchmark binary with 
`bloom::update::contains_and_insert --repeat 1 --raw`.
   
   | Workload              | Rounds | Before median (range), ms | After median 
(range), ms | Time change |
   | --------------------- | -----: | ------------------------: | 
-----------------------: | ----------: |
   | All present           |  2,000 |             178 (174–182) |            
196 (194–202) |      +10.1% |
   | All initially absent  |  1,000 |             250 (245–259) |            
118 (116–131) |      −52.8% |
   | Half present / absent |  1,000 |             231 (230–236) |            
140 (137–142) |      −39.4% |
   | Initially empty       |  1,000 |             218 (213–230) |            
130 (125–141) |      −40.4% |
   
   The tradeoff is approximately 10% more time for the all-present workload in 
exchange for substantially lower time on workloads containing new keys.
   
   ## Validation
   
   - `cargo x check`: passed the complete feature matrix.
   - `cargo x test`: 742 passed, including 135 doctests and the Java/C++/Go 
serialization fixtures.
   - `cargo x lint`: passed Clippy, rustfmt, rustdoc, Taplo, typos, and license 
checks.
   - `cargo x bench -- --test`: all 324 benchmark implementations passed.
   - Rust 1.86.0: all 9 Bloom behavior tests and the reducer boundary test 
passed.
   - Additional Node-hosted wasm32 execution: 32 size/hash-count combinations 
passed direct-remainder bit-layout comparisons, membership/update agreement, 
repeated updates, and population-count checks.
   
   Follow-up to #359.
   
   


-- 
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]

Reply via email to