TwoX-Hash

A pure Rust implementation of the xxHash and XXH3 non-cryptographic hashing algorithms.

Library
Cargo
v2.1.3
437stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
60/100Good
Development Activity60
Maintenance28
Community72
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
75/100Good
Architecture74
Code Quality78
Innovation76
Learning Curve72

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/BuildHasher implementation that plugs directly into std::collections::HashMap and HashSet
  • 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 std feature for maximum throughput
  • Optional serialize feature 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/HashSet for 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search