foldhash

A fast, non-cryptographic, DoS-resistant hashing algorithm for Rust data structures.

Library
Cargo
v0.2.0
366stars
Zlib

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
43/100Fair
Development Activity32
Maintenance4
Community52
Maturity44
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
84/100Excellent
Architecture86
Code Quality85
Innovation84
Learning Curve82

foldhash is a fast, non-cryptographic hashing algorithm implemented in Rust, designed for computational uses such as hash maps, bloom filters, and count/HyperLogLog sketching. It is minimally DoS-resistant by default via randomized internal state, while being dramatically faster than SipHash (Rust’s standard default) and competitive with or faster than aHash and fxhash.

The crate ships two variants: foldhash::fast, optimized for raw throughput in structures like hash maps, and foldhash::quality, optimized for statistical distribution in algorithms like HyperLogLog and MinHash. It works in #![no_std] environments by disabling the default std feature.

What You Get

  • A fast non-cryptographic hasher usable as a BuildHasher for HashMap/HashSet
  • Two variants: foldhash::fast for throughput and foldhash::quality for statistical quality
  • Minimal HashDoS resistance through randomized per-instance internal state
  • #![no_std] support by disabling the default std feature
  • Performance competitive with or exceeding aHash and fxhash, far ahead of SipHash

Common Use Cases

  • Speeding up HashMap/HashSet lookups by swapping the default hasher
  • Hashing keys in bloom filters and count sketches
  • Providing well-distributed hashes for HyperLogLog and MinHash cardinality estimation
  • Hashing in embedded or no_std contexts where SipHash is too slow

Under The Hood

Architecture - foldhash centers on a folded-multiply mixing scheme: the core combines input words with multiplications and folds the 128-bit product back to 64 bits, seeded by randomized state to resist trivial collision attacks. The crate splits into fast and quality modules, each exposing a FoldHasher plus RandomState/FixedState builders that implement Rust’s BuildHasher trait. Tech Stack - Pure Rust with no runtime dependencies, gated by a std default feature so it degrades cleanly to no_std; it relies only on core integer arithmetic, making it portable across targets. Code Quality - The repository documents its design and threat model thoroughly in the README (including explicit non-goals around cryptography and cross-version stability) and benchmarks against aHash, fxhash, and SipHash; its enormous download count (400M+) reflects wide adoption, notably as hashbrown/std HashMap’s fast hasher. API Design - Usage is idiomatic: HashMap::with_hasher(foldhash::fast::RandomState::default()), mirroring the standard BuildHasher pattern, so adoption requires no new mental model. Clear guidance on when not to use it (persistence, security) keeps misuse low.

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