Skip to content

Commit 1aa5e96

Browse files
committed
Switch to foldhash-portable and add generic BuildHasher support
- Replace xxhash-rust with foldhash-portable (portable feature) - Add S: BuildHasher generic parameter to Filter and Builder - Preserve hasher across grow/shrink/merge via S: Clone - Add _with_hasher constructors for Filter; Builder::new(filter) takes an empty Filter - Add Filter::with_hasher() for swapping hasher (e.g. after deserialization) - Remove StableHasher LE normalization (foldhash-portable handles it) - Keep usize/isize → u64/i64 widening for 32-bit compatibility - Add cross-platform hash stability test (verified on x86_64 LE + PowerPC 32-bit BE) - Add cross-platform CI job (powerpc, i686, aarch64) - Document T: Hash stability caveats and custom hasher usage
1 parent e5a9982 commit 1aa5e96

File tree

5 files changed

+475
-159
lines changed

5 files changed

+475
-159
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ jobs:
3636
- run: cargo test --no-default-features
3737
- run: cargo test --all-features
3838

39+
cross-platform-test:
40+
name: Cross-platform tests
41+
runs-on: ubuntu-latest
42+
strategy:
43+
matrix:
44+
target:
45+
- powerpc-unknown-linux-gnu # 32-bit big-endian
46+
- i686-unknown-linux-gnu # 32-bit little-endian
47+
- aarch64-unknown-linux-gnu # 64-bit little-endian (ARM)
48+
steps:
49+
- uses: actions/checkout@v4
50+
- uses: dtolnay/rust-toolchain@stable
51+
- uses: taiki-e/install-action@v2
52+
with:
53+
tool: cross
54+
- run: cross test --features serde --target ${{ matrix.target }} --lib
55+
3956
fuzz-tests:
4057
name: Fuzz tests
4158
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jsonschema = ["schemars"]
1919
serde = ["dep:serde", "dep:serde_bytes"]
2020

2121
[dependencies]
22-
xxhash-rust = { version = "0.8.12", features = ["xxh3"] }
22+
foldhash-portable = { version = "0.2.0", features = ["portable"] }
2323
serde = { optional = true, version = "1", features = ["derive"] }
2424
serde_bytes = { optional = true, version = "0.11" }
2525
schemars = { optional = true, version = "1" }

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ for i in 0..1000 {
4242

4343
### Hasher
4444

45-
The hashing algorithm used is [xxhash3](https://crates.io/crates/xxhash-rust) which offers both high performance and stability across platforms.
45+
Methods accepting `T: Hash` are provided for convenience using [foldhash-portable](https://crates.io/crates/foldhash-portable), which offers high performance and stability across platforms. Note that a fixed seed is used (no DoS resistance) and `#[derive(Hash)]` output is [not guaranteed stable](https://github.com/hoxxep/portable-hash#whats-wrong-with-the-stdhash-traits) across Rust compiler versions.
46+
47+
`Filter` supports a custom `BuildHasher` via its `S` type parameter (similar to `HashMap`). Use `Filter::new_with_hasher()` and related constructors. The hasher is not serialized; on deserialization it is reconstructed via `S::default()`. If that doesn't produce the correct hasher, use `Filter::with_hasher()` to restore it. Filters being merged must use the same hasher.
4648

4749
### Filter size
4850

0 commit comments

Comments
 (0)