Skip to content

Commit 299d950

Browse files
authored
Merge pull request #134 from cuviper/hashers
Demonstrate fnv and fxhash as alternate hashers
2 parents 43b5fac + abda9b9 commit 299d950

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ rand = {version = "0.7", features = ["small_rng"] }
4141
quickcheck = { version = "0.9", default-features = false }
4242
fnv = "1.0"
4343
lazy_static = "1.3"
44+
fxhash = "0.2.1"
4445

4546
[features]
4647
# Serialization with serde 1.0

src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,33 @@
2424
//! - The [`MutableKeys`][map::MutableKeys] trait, which gives opt-in mutable
2525
//! access to hash map keys.
2626
//!
27+
//! ### Alternate Hashers
28+
//!
29+
//! [`IndexMap`] and [`IndexSet`] have a default hasher type `S = RandomState`,
30+
//! just like the standard `HashMap` and `HashSet`, which is resistant to
31+
//! HashDoS attacks but not the most performant. Type aliases can make it easier
32+
//! to use alternate hashers:
33+
//!
34+
//! ```
35+
//! # extern crate fnv;
36+
//! # extern crate fxhash;
37+
//! use fnv::FnvBuildHasher;
38+
//! use fxhash::FxBuildHasher;
39+
//! use indexmap::{IndexMap, IndexSet};
40+
//!
41+
//! type FnvIndexMap<K, V> = IndexMap<K, V, FnvBuildHasher>;
42+
//! type FnvIndexSet<T> = IndexSet<T, FnvBuildHasher>;
43+
//!
44+
//! type FxIndexMap<K, V> = IndexMap<K, V, FxBuildHasher>;
45+
//! type FxIndexSet<T> = IndexSet<T, FxBuildHasher>;
46+
//!
47+
//! let std: IndexSet<i32> = (0..100).collect();
48+
//! let fnv: FnvIndexSet<i32> = (0..100).collect();
49+
//! let fx: FxIndexSet<i32> = (0..100).collect();
50+
//! assert_eq!(std, fnv);
51+
//! assert_eq!(std, fx);
52+
//! ```
53+
//!
2754
//! ### Rust Version
2855
//!
2956
//! This version of indexmap requires Rust 1.18 or later, or 1.32+ for

0 commit comments

Comments
 (0)