Skip to content

Commit 182d3e3

Browse files
committed
Replace FxHash with AHash as the default hasher
1 parent ed0b240 commit 182d3e3

File tree

5 files changed

+14
-124
lines changed

5 files changed

+14
-124
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ edition = "2018"
1313
build = "build.rs"
1414

1515
[dependencies]
16+
# For the default hasher
17+
ahash = { version = "0.2", optional = true }
18+
1619
# For external trait impls
1720
rayon = { version = "1.0", optional = true }
1821
serde = { version = "1.0.25", default-features = false, optional = true }
@@ -34,7 +37,7 @@ serde_test = "1.0"
3437
doc-comment = "0.3.1"
3538

3639
[features]
37-
default = []
40+
default = ["ahash"]
3841
nightly = []
3942
rustc-internal-api = []
4043
rustc-dep-of-std = ["nightly", "core", "compiler_builtins", "alloc", "rustc-internal-api"]

src/fx.rs

Lines changed: 0 additions & 119 deletions
This file was deleted.

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ doc_comment::doctest!("../README.md");
4444
mod macros;
4545

4646
mod external_trait_impls;
47-
mod fx;
4847
mod map;
4948
mod raw;
5049
#[cfg(feature = "rustc-internal-api")]

src/map.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ use core::marker::PhantomData;
88
use core::mem;
99
use core::ops::Index;
1010

11-
pub use crate::fx::FxHashBuilder as DefaultHashBuilder;
11+
/// Default hasher for `HashMap`.
12+
#[cfg(feature = "ahash")]
13+
pub type DefaultHashBuilder = ahash::ABuildHasher;
14+
15+
/// Dummy default hasher for `HashMap`.
16+
#[cfg(not(feature = "ahash"))]
17+
pub enum DefaultHashBuilder {}
1218

1319
/// A hash map implemented with quadratic probing and SIMD lookup.
1420
///
@@ -183,7 +189,6 @@ pub use crate::fx::FxHashBuilder as DefaultHashBuilder;
183189
/// // use the values stored in map
184190
/// }
185191
/// ```
186-
187192
#[derive(Clone)]
188193
pub struct HashMap<K, V, S = DefaultHashBuilder> {
189194
pub(crate) hash_builder: S,
@@ -197,6 +202,7 @@ pub(crate) fn make_hash<K: Hash + ?Sized>(hash_builder: &impl BuildHasher, val:
197202
state.finish()
198203
}
199204

205+
#[cfg(feature = "ahash")]
200206
impl<K, V> HashMap<K, V, DefaultHashBuilder> {
201207
/// Creates an empty `HashMap`.
202208
///
@@ -227,7 +233,7 @@ impl<K, V> HashMap<K, V, DefaultHashBuilder> {
227233
/// ```
228234
#[inline]
229235
pub fn with_capacity(capacity: usize) -> Self {
230-
Self::with_capacity_and_hasher(capacity, DefaultHashBuilder::default())
236+
Self::with_capacity_and_hasher(capacity, Default::default())
231237
}
232238
}
233239

src/set.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pub struct HashSet<T, S = DefaultHashBuilder> {
116116
pub(crate) map: HashMap<T, (), S>,
117117
}
118118

119+
#[cfg(feature = "ahash")]
119120
impl<T: Hash + Eq> HashSet<T, DefaultHashBuilder> {
120121
/// Creates an empty `HashSet`.
121122
///

0 commit comments

Comments
 (0)