TwoX-Hash
A pure Rust implementation of the xxHash and XXH3 non-cryptographic hashing algorithms.
Repository Health
Technical Analysis
TwoX-Hash brings the xxHash family of algorithms to Rust, covering XxHash32, XxHash64, XxHash3_64, and XxHash3_128 behind a single crate with feature flags to opt into only what you need. It implements the standard Hasher trait so it drops into HashMap/HashSet as a BuildHasher, and also exposes streaming and one-shot APIs for hashing arbitrary byte buffers outside of collections.
The crate is widely used as a fast alternative to Rust’s default SipHash-based hasher in performance-sensitive code, and its XXH3 implementation includes SIMD-accelerated paths (SSE2, AVX2, NEON) for high-throughput checksumming, deduplication, and content-addressing workloads.
What You Get
- Four algorithm variants (XxHash32, XxHash64, XxHash3_64, XxHash3_128) selectable via Cargo feature flags
- A
Hasher/BuildHasherimplementation that plugs directly intostd::collections::HashMapandHashSet - One-shot hashing functions for hashing a byte slice in a single call, plus streaming
write()support for incremental data - SIMD-accelerated XXH3 code paths (SSE2/AVX2/NEON) gated behind the
stdfeature for maximum throughput - Optional
serializefeature for Serde-based (de)serialization of hasher state no_std/alloc-compatible builds for embedded and constrained environments
Common Use Cases
- Replacing the default SipHash hasher in
HashMap/HashSetfor CPU-bound workloads where DoS resistance isn’t required - Computing fast checksums or content fingerprints for deduplication and caching layers
- Hashing large files or streams incrementally without loading them fully into memory
- Building content-addressed storage or diffing systems that need a stable, high-speed non-cryptographic digest
Under The Hood
Architecture - The crate is a Cargo workspace rooted on the twox-hash library itself, with separate xx_hash-sys (FFI bindings to the reference C implementation used for testing/benchmarking), comparison (benchmark harness against other hashers), and twox-hash-sum (a small CLI checksumming tool) members; the library crate’s src/ splits each algorithm (xxhash32.rs, xxhash64.rs, xxhash3.rs, xxhash3_64.rs, xxhash3_128.rs) into its own module behind a matching Cargo feature, with lib.rs re-exporting the enabled variants. Tech Stack - Pure Rust with 2021 edition and MSRV 1.81, zero mandatory runtime dependencies; optional rand for random seed generation and serde for state (de)serialization are both feature-gated so the default build stays lean. Code Quality - Doc examples embedded in the README and crate docs double as doctests, and the workspace’s comparison and xx_hash-sys members provide cross-validation against the canonical C xxHash implementation and other Rust hashers; the #[lints.rust.unexpected_cfgs] table in Cargo.toml shows care taken around the SIMD feature-detection cfg flags. API Design - The public surface follows the standard library’s Hasher/BuildHasher conventions closely (with_seed, write, finish), which keeps the learning curve low for anyone who has used a custom hasher in Rust before, and the one-shot oneshot() functions cover the common case of hashing a single buffer without needing to understand the streaming API at all.
Used by 3 apps in this directory
AppFlowy
Productivity · Project Management · Collaboration
The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.
Meilisearch
Search
Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.
Sonic
Databases · Search
Fast, lightweight, schema-less search backend in Rust — microsecond queries, 30MB RAM, no document storage required.