Speedy non-cryptographic hashing algorithm used by rustc
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Reynard User 178067a2c7
Some checks failed
Rust / cross-test (mips-unknown-linux-gnu) (push) Has been cancelled
Rust / cross-test (mips64-unknown-linux-gnuabi64) (push) Has been cancelled
Rust / cross-test (x86_64-unknown-linux-gnu) (push) Has been cancelled
Rust / fmt (push) Has been cancelled
Rust / docs (push) Has been cancelled
Rust / clippy (push) Has been cancelled
Rust / test (macos) (push) Has been cancelled
Rust / test (ubuntu) (push) Has been cancelled
Rust / test (windows) (push) Has been cancelled
Rust / cross-test (i686-unknown-linux-gnu) (push) Has been cancelled
chore: sync dependencies (monorepo)
2026-04-13 10:55:48 +02:00
.github/workflows Be consistent around the installation of the different toolchains 2024-07-18 11:51:43 +02:00
src style: use consistent range format 2026-03-25 11:16:48 -06:00
.gitignore Remove Cargo.lock 2018-05-28 17:57:47 +02:00
Cargo.toml chore: sync dependencies (monorepo) 2026-04-13 10:55:48 +02:00
CHANGELOG.md Prepare 2.1.2 2026-03-25 19:56:16 +01:00
CODE_OF_CONDUCT.md Replace Code of Conduct with link 2024-03-01 12:34:57 -05:00
LICENSE-APACHE Remove appendix from APACHE license 2024-03-01 12:40:59 -05:00
LICENSE-MIT Remove newline to be consistent with rust-lang/rust 2024-03-01 12:40:59 -05:00
README.md Bump to version 2.1.0 2024-11-30 14:42:51 +01:00

rustc-hash

crates.io Documentation

A speedy, non-cryptographic hashing algorithm used by rustc. The hash map in std uses SipHash by default, which provides resistance against DOS attacks. These attacks aren't a concern in the compiler so we prefer to use a quicker, non-cryptographic hash algorithm.

The original hash algorithm provided by this crate was one taken from Firefox, hence the hasher it provides is called FxHasher. This name is kept for backwards compatibility, but the underlying hash has since been replaced. The current design for the hasher is a polynomial hash finished with a single bit rotation, together with a wyhash-inspired compression function for strings/slices, both designed by Orson Peters.

For rustc we have tried many different hashing algorithms. Hashing speed is critical, especially for single integers. Spending more CPU cycles on a higher quality hash does not reduce hash collisions enough to make the compiler faster on real-world benchmarks.

Usage

This crate provides FxHashMap and FxHashSet as collections. They are simply type aliases for their std::collection counterparts using the Fx hasher.

use rustc_hash::FxHashMap;

let mut map: FxHashMap<u32, u32> = FxHashMap::default();
map.insert(22, 44);

no_std

The std feature is on by default to enable collections. It can be turned off in Cargo.toml like so:

rustc-hash = { version = "2.1", default-features = false }