add some minimal comments

This commit is contained in:
Niko Matsakis 2018-05-24 08:36:14 -04:00
parent 138f76c56d
commit 673454b272
2 changed files with 21 additions and 11 deletions

View File

@ -12,3 +12,10 @@ 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 map: FxHashMap<u32, u32> = FxHashMap::default();
```

View File

@ -8,24 +8,27 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Fast, non-cryptographic hash used by rustc and Firefox.
//!
//! # Example
//!
//! ```rust
//! use rustc_hash::FxHashMap;
//! let mut map: FxHashMap<u32, u32> = FxHashMap::default();
//! map.insert(22, 44);
//! ```
use std::collections::{HashMap, HashSet};
use std::default::Default;
use std::hash::{Hasher, Hash, BuildHasherDefault};
use std::hash::{Hasher, BuildHasherDefault};
use std::ops::BitXor;
/// Type alias for a hashmap using the `fx` hash algorithm.
pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
/// Type alias for a hashmap using the `fx` hash algorithm.
pub type FxHashSet<V> = HashSet<V, BuildHasherDefault<FxHasher>>;
#[allow(non_snake_case)]
pub fn FxHashMap<K: Hash + Eq, V>() -> FxHashMap<K, V> {
HashMap::default()
}
#[allow(non_snake_case)]
pub fn FxHashSet<V: Hash + Eq>() -> FxHashSet<V> {
HashSet::default()
}
/// A speedy hash algorithm for use 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