Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rust-lang/rustc-hash
Custom hash algorithm used by rustc (plus hashmap/set aliases): fast, deterministic, not secure
https://github.com/rust-lang/rustc-hash
Last synced: about 1 month ago
JSON representation
Custom hash algorithm used by rustc (plus hashmap/set aliases): fast, deterministic, not secure
- Host: GitHub
- URL: https://github.com/rust-lang/rustc-hash
- Owner: rust-lang
- License: apache-2.0
- Created: 2018-05-24T12:26:21.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-22T18:18:27.000Z (6 months ago)
- Last Synced: 2024-05-22T19:36:29.824Z (6 months ago)
- Language: Rust
- Size: 42 KB
- Stars: 317
- Watchers: 25
- Forks: 40
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# rustc-hash
[![crates.io](https://img.shields.io/crates/v/rustc-hash.svg)](https://crates.io/crates/rustc-hash)
[![Documentation](https://docs.rs/rustc-hash/badge.svg)](https://docs.rs/rustc-hash)A speedy, non-cryptographic hashing algorithm used by `rustc`.
The [hash map in `std`](https://doc.rust-lang.org/std/collections/struct.HashMap.html) 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.```rust
use rustc_hash::FxHashMap;let mut map: FxHashMap = 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:```toml
rustc-hash = { version = "2.0", default-features = false }
```