mirror of
https://gitee.com/openharmony/third_party_rust_rustc-hash
synced 2024-11-26 17:40:28 +00:00
add some minimal comments
This commit is contained in:
parent
138f76c56d
commit
673454b272
@ -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();
|
||||
```
|
||||
|
25
src/lib.rs
25
src/lib.rs
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user