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

   ## Summary
   
   This pull request polishes the `datasketches::xor` public API, fixes 
duplicate-hash detection during `XorFilter` construction, and adds filter 
inspection accessors.
   
   ## Problem
   
   1. `XorFilterBuilder` mutation methods returned `()` and `build(mut self)` 
consumed the builder, preventing single-expression chaining 
(`XorFilterBuilder::new(...).update_values(...).build()`) and forcing callers 
to re-accumulate hashes if they needed to change the construction seed or retry.
   2. `XorFilter::from_hashes_with_seed` detected duplicate hashes only via 
degree-2 XOR mask cancellation (`count == 2 && xor_mask == 0`), which misses 
duplicates with odd or higher multiplicities such as `[1, 1, 1]` and wastes 100 
peeling attempts before reporting a layout failure instead of a duplicate-hash 
error.
   3. `XorFilter` lacked `seed()` and `capacity()` accessors to inspect the 
winning mixing seed and total slot capacity stored in the filter, 
`from_hashes*` named its parameter `keys` instead of `hashes`, and 
`XorFilterType`, `XorFilterBuilder`, `XorFilter`, and pure query/serialization 
methods lacked `#[must_use]`.
   
   ## Changes
   
   - **Builder chaining and reseeding (`XorFilterBuilder`)**: Added 
`XorFilterBuilder::seed(&mut self, seed: u64) -> &mut Self`, changed `update`, 
`update_hash`, `update_values`, and `update_hashes` to return `&mut Self` 
(without `#[must_use]` so imperative loops compile cleanly), and changed 
`build(&mut self) -> Result<XorFilter, Error>` to sort and deduplicate 
accumulated hashes in place while retaining them across builds. Updated the 
`datasketches::xor` module example to show chaining.
   - **Complete duplicate detection (`XorFilter::from_hashes*`)**: Renamed 
`keys` to `hashes` on `XorFilter::from_hashes`, 
`XorFilter::from_hashes_with_seed`, and the internal `map` helper, clarified 
docstrings contrasting `from_hashes*` (fast path for distinct hashes; rejects 
duplicates) against `XorFilterBuilder` (auto-deduplicates), and replaced the 
degree-2 XOR cancellation check with a fallback sort-and-adjacent-scan check on 
`stack_hash` when attempt `0` fails to peel, catching duplicates of any 
multiplicity without adding cost to the fast first-attempt path.
   - **Inspection accessors and `#[must_use]`**: Added `XorFilter::seed(&self) 
-> u64` and `XorFilter::capacity(&self) -> u64` (and included `capacity` in 
`Debug` output), and annotated `XorFilterType`, `XorFilterBuilder`, 
`XorFilter`, and pure query/serialization methods with `#[must_use]`.
   - **Tests**: Added integration and serialization tests covering builder 
chaining, reseeding and incremental reuse, multiplicity-3 and -4 duplicate 
rejection, and `seed()` / `capacity()` parity across round-trips and Java 
reference fixtures.
   
   ## Validation
   
   - `cargo x check`
   - `cargo x test` (744 passed, 0 failed, 0 ignored)
   - `cargo x lint`
   - `cargo +1.86.0 check -p datasketches --all-features`
   


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