| 1 |
# rustc-hash |
| 2 |
|
| 3 |
[](https://crates.io/crates/rustc-hash) |
| 4 |
[](https://docs.rs/rustc-hash) |
| 5 |
|
| 6 |
A speedy hash algorithm used within rustc. The hashmap in liballoc by |
| 7 |
default uses SipHash which isn't quite as speedy as we want. In the |
| 8 |
compiler we're not really worried about DOS attempts, so we use a fast |
| 9 |
non-cryptographic hash. |
| 10 |
|
| 11 |
This is the same as the algorithm used by Firefox -- which is a |
| 12 |
homespun one not based on any widely-known algorithm -- though |
| 13 |
modified to produce 64-bit hash values instead of 32-bit hash |
| 14 |
values. It consistently out-performs an FNV-based hash within rustc |
| 15 |
itself -- the collision rate is similar or slightly worse than FNV, |
| 16 |
but the speed of the hash function itself is much higher because it |
| 17 |
works on up to 8 bytes at a time. |
| 18 |
|
| 19 |
## Usage |
| 20 |
|
| 21 |
```rust |
| 22 |
use rustc_hash::FxHashMap; |
| 23 |
|
| 24 |
let mut map: FxHashMap<u32, u32> = FxHashMap::default(); |
| 25 |
map.insert(22, 44); |
| 26 |
``` |
| 27 |
|
| 28 |
### `no_std` |
| 29 |
|
| 30 |
This crate can be used as a `no_std` crate by disabling the `std` |
| 31 |
feature, which is on by default, as follows: |
| 32 |
|
| 33 |
```toml |
| 34 |
rustc-hash = { version = "1.0", default-features = false } |
| 35 |
``` |
| 36 |
|
| 37 |
In this configuration, `FxHasher` is the only export, and the |
| 38 |
`FxHashMap`/`FxHashSet` type aliases are omitted. |