11e15f31bSopenharmony_ci# rustc-hash 21e15f31bSopenharmony_ci 31e15f31bSopenharmony_ci[](https://crates.io/crates/rustc-hash) 41e15f31bSopenharmony_ci[](https://docs.rs/rustc-hash) 51e15f31bSopenharmony_ci 61e15f31bSopenharmony_ciA speedy hash algorithm used within rustc. The hashmap in liballoc by 71e15f31bSopenharmony_cidefault uses SipHash which isn't quite as speedy as we want. In the 81e15f31bSopenharmony_cicompiler we're not really worried about DOS attempts, so we use a fast 91e15f31bSopenharmony_cinon-cryptographic hash. 101e15f31bSopenharmony_ci 111e15f31bSopenharmony_ciThis is the same as the algorithm used by Firefox -- which is a 121e15f31bSopenharmony_cihomespun one not based on any widely-known algorithm -- though 131e15f31bSopenharmony_cimodified to produce 64-bit hash values instead of 32-bit hash 141e15f31bSopenharmony_civalues. It consistently out-performs an FNV-based hash within rustc 151e15f31bSopenharmony_ciitself -- the collision rate is similar or slightly worse than FNV, 161e15f31bSopenharmony_cibut the speed of the hash function itself is much higher because it 171e15f31bSopenharmony_ciworks on up to 8 bytes at a time. 181e15f31bSopenharmony_ci 191e15f31bSopenharmony_ci## Usage 201e15f31bSopenharmony_ci 211e15f31bSopenharmony_ci```rust 221e15f31bSopenharmony_ciuse rustc_hash::FxHashMap; 231e15f31bSopenharmony_ci 241e15f31bSopenharmony_cilet mut map: FxHashMap<u32, u32> = FxHashMap::default(); 251e15f31bSopenharmony_cimap.insert(22, 44); 261e15f31bSopenharmony_ci``` 271e15f31bSopenharmony_ci 281e15f31bSopenharmony_ci### `no_std` 291e15f31bSopenharmony_ci 301e15f31bSopenharmony_ciThis crate can be used as a `no_std` crate by disabling the `std` 311e15f31bSopenharmony_cifeature, which is on by default, as follows: 321e15f31bSopenharmony_ci 331e15f31bSopenharmony_ci```toml 341e15f31bSopenharmony_cirustc-hash = { version = "1.1", default-features = false } 351e15f31bSopenharmony_ci``` 361e15f31bSopenharmony_ci 371e15f31bSopenharmony_ciIn this configuration, `FxHasher` is the only export, and the 381e15f31bSopenharmony_ci`FxHashMap`/`FxHashSet` type aliases are omitted. 39