#hash #rustc #fxhash

no-std rustc-hash

speed, non-cryptographic hash used in rustc

3 stable releases

Uses old Rust 2015

1.1.0 Feb 8, 2020
1.0.1 May 28, 2018
1.0.0 May 24, 2018

#26 in Algorithms

Download history 762234/week @ 2023-11-21 923334/week @ 2023-11-28 935552/week @ 2023-12-05 958595/week @ 2023-12-12 779008/week @ 2023-12-19 484269/week @ 2023-12-26 875610/week @ 2024-01-02 964512/week @ 2024-01-09 1008248/week @ 2024-01-16 1012890/week @ 2024-01-23 1063988/week @ 2024-01-30 1072546/week @ 2024-02-06 1026473/week @ 2024-02-13 1213605/week @ 2024-02-20 1126791/week @ 2024-02-27 909437/week @ 2024-03-05

4,454,030 downloads per month
Used in 10,289 crates (611 directly)

Apache-2.0/MIT

10KB
93 lines

rustc-hash

crates.io Documentation

A speedy hash algorithm used within rustc. The hashmap in liballoc by default uses SipHash which isn't quite as speedy as we want. In the compiler we're not really worried about DOS attempts, so we use a fast non-cryptographic hash.

This is the same as the algorithm used by Firefox -- which is a homespun one not based on any widely-known algorithm -- though modified to produce 64-bit hash values instead of 32-bit hash values. It consistently out-performs an FNV-based hash within rustc itself -- the collision rate is similar or slightly worse than FNV, but the speed of the hash function itself is much higher because it works on up to 8 bytes at a time.

Usage

use rustc_hash::FxHashMap;

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

no_std

This crate can be used as a no_std crate by disabling the std feature, which is on by default, as follows:

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

In this configuration, FxHasher is the only export, and the FxHashMap/FxHashSet type aliases are omitted.

No runtime deps

Features