Skip to content

Commit

Permalink
Use DefaultHashBuilder instead of AHasher in docs and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Jun 19, 2024
1 parent 369ad20 commit e2b6b85
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 174 deletions.
2 changes: 1 addition & 1 deletion benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate test;

use test::{black_box, Bencher};

use hashbrown::hash_map::DefaultHashBuilder;
use hashbrown::DefaultHashBuilder;
use hashbrown::{HashMap, HashSet};
use std::{
collections::hash_map::RandomState,
Expand Down
5 changes: 1 addition & 4 deletions src/external_trait_impls/rayon/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,7 @@ mod test_par_table {

use rayon::prelude::*;

use crate::{
hash_map::{make_hash, DefaultHashBuilder},
hash_table::HashTable,
};
use crate::{hash_map::make_hash, hash_table::HashTable, DefaultHashBuilder};

#[test]
fn test_iterate() {
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
#![cfg_attr(feature = "nightly", warn(fuzzy_provenance_casts))]
#![cfg_attr(feature = "nightly", allow(internal_features))]

/// Default hasher for [`HashMap`], [`HashSet`] and [`HashTable`].
#[cfg(feature = "default-hasher")]
pub type DefaultHashBuilder = core::hash::BuildHasherDefault<ahash::AHasher>;

/// Dummy default hasher for [`HashMap`], [`HashSet`] and [`HashTable`].
#[cfg(not(feature = "default-hasher"))]
pub enum DefaultHashBuilder {}

#[cfg(test)]
#[macro_use]
extern crate std;
Expand Down
20 changes: 6 additions & 14 deletions src/map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::raw::{
Allocator, Bucket, Global, RawDrain, RawExtractIf, RawIntoIter, RawIter, RawTable,
};
use crate::{Equivalent, TryReserveError};
use crate::{DefaultHashBuilder, Equivalent, TryReserveError};
use core::borrow::Borrow;
use core::fmt::{self, Debug};
use core::hash::{BuildHasher, Hash};
Expand All @@ -10,14 +10,6 @@ use core::marker::PhantomData;
use core::mem;
use core::ops::Index;

/// Default hasher for `HashMap`.
#[cfg(feature = "default-hasher")]
pub type DefaultHashBuilder = core::hash::BuildHasherDefault<ahash::AHasher>;

/// Dummy default hasher for `HashMap`.
#[cfg(not(feature = "default-hasher"))]
pub enum DefaultHashBuilder {}

/// A hash map implemented with quadratic probing and SIMD lookup.
///
/// The default hashing algorithm is currently [`AHash`], though this is
Expand Down Expand Up @@ -447,7 +439,7 @@ impl<K, V, S> HashMap<K, V, S> {
///
/// ```
/// use hashbrown::HashMap;
/// use hashbrown::hash_map::DefaultHashBuilder;
/// use hashbrown::DefaultHashBuilder;
///
/// let s = DefaultHashBuilder::default();
/// let mut map = HashMap::with_hasher(s);
Expand Down Expand Up @@ -489,7 +481,7 @@ impl<K, V, S> HashMap<K, V, S> {
///
/// ```
/// use hashbrown::HashMap;
/// use hashbrown::hash_map::DefaultHashBuilder;
/// use hashbrown::DefaultHashBuilder;
///
/// let s = DefaultHashBuilder::default();
/// let mut map = HashMap::with_capacity_and_hasher(10, s);
Expand Down Expand Up @@ -535,7 +527,7 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
///
/// ```
/// use hashbrown::HashMap;
/// use hashbrown::hash_map::DefaultHashBuilder;
/// use hashbrown::DefaultHashBuilder;
///
/// let s = DefaultHashBuilder::default();
/// let mut map = HashMap::with_hasher(s);
Expand Down Expand Up @@ -570,7 +562,7 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
///
/// ```
/// use hashbrown::HashMap;
/// use hashbrown::hash_map::DefaultHashBuilder;
/// use hashbrown::DefaultHashBuilder;
///
/// let s = DefaultHashBuilder::default();
/// let mut map = HashMap::with_capacity_and_hasher(10, s);
Expand All @@ -592,7 +584,7 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
///
/// ```
/// use hashbrown::HashMap;
/// use hashbrown::hash_map::DefaultHashBuilder;
/// use hashbrown::DefaultHashBuilder;
///
/// let hasher = DefaultHashBuilder::default();
/// let map: HashMap<i32, i32> = HashMap::with_hasher(hasher);
Expand Down
6 changes: 3 additions & 3 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ impl<T> Bucket<T> {
/// use core::hash::{BuildHasher, Hash};
/// use hashbrown::raw::{Bucket, RawTable};
///
/// type NewHashBuilder = core::hash::BuildHasherDefault<ahash::AHasher>;
/// type NewHashBuilder = hashbrown::DefaultHashBuilder;
///
/// fn make_hash<K: Hash + ?Sized, S: BuildHasher>(hash_builder: &S, key: &K) -> u64 {
/// use core::hash::Hasher;
Expand Down Expand Up @@ -649,7 +649,7 @@ impl<T> Bucket<T> {
/// use core::hash::{BuildHasher, Hash};
/// use hashbrown::raw::{Bucket, RawTable};
///
/// type NewHashBuilder = core::hash::BuildHasherDefault<ahash::AHasher>;
/// type NewHashBuilder = hashbrown::DefaultHashBuilder;
///
/// fn make_hash<K: Hash + ?Sized, S: BuildHasher>(hash_builder: &S, key: &K) -> u64 {
/// use core::hash::Hasher;
Expand Down Expand Up @@ -708,7 +708,7 @@ impl<T> Bucket<T> {
/// use core::hash::{BuildHasher, Hash};
/// use hashbrown::raw::{Bucket, RawTable};
///
/// type NewHashBuilder = core::hash::BuildHasherDefault<ahash::AHasher>;
/// type NewHashBuilder = hashbrown::DefaultHashBuilder;
///
/// fn make_hash<K: Hash + ?Sized, S: BuildHasher>(hash_builder: &S, key: &K) -> u64 {
/// use core::hash::Hasher;
Expand Down
15 changes: 8 additions & 7 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use core::hash::{BuildHasher, Hash};
use core::iter::{Chain, FusedIterator};
use core::ops::{BitAnd, BitOr, BitXor, Sub};

use super::map::{self, DefaultHashBuilder, HashMap, Keys};
use super::map::{self, HashMap, Keys};
use crate::raw::{Allocator, Global, RawExtractIf};
use crate::DefaultHashBuilder;

// Future Optimization (FIXME!)
// =============================
Expand Down Expand Up @@ -459,7 +460,7 @@ impl<T, S> HashSet<T, S, Global> {
///
/// ```
/// use hashbrown::HashSet;
/// use hashbrown::hash_map::DefaultHashBuilder;
/// use hashbrown::DefaultHashBuilder;
///
/// let s = DefaultHashBuilder::default();
/// let mut set = HashSet::with_hasher(s);
Expand Down Expand Up @@ -497,7 +498,7 @@ impl<T, S> HashSet<T, S, Global> {
///
/// ```
/// use hashbrown::HashSet;
/// use hashbrown::hash_map::DefaultHashBuilder;
/// use hashbrown::DefaultHashBuilder;
///
/// let s = DefaultHashBuilder::default();
/// let mut set = HashSet::with_capacity_and_hasher(10, s);
Expand Down Expand Up @@ -546,7 +547,7 @@ where
///
/// ```
/// use hashbrown::HashSet;
/// use hashbrown::hash_map::DefaultHashBuilder;
/// use hashbrown::DefaultHashBuilder;
///
/// let s = DefaultHashBuilder::default();
/// let mut set = HashSet::with_hasher(s);
Expand Down Expand Up @@ -584,7 +585,7 @@ where
///
/// ```
/// use hashbrown::HashSet;
/// use hashbrown::hash_map::DefaultHashBuilder;
/// use hashbrown::DefaultHashBuilder;
///
/// let s = DefaultHashBuilder::default();
/// let mut set = HashSet::with_capacity_and_hasher(10, s);
Expand All @@ -605,7 +606,7 @@ where
///
/// ```
/// use hashbrown::HashSet;
/// use hashbrown::hash_map::DefaultHashBuilder;
/// use hashbrown::DefaultHashBuilder;
///
/// let hasher = DefaultHashBuilder::default();
/// let set: HashSet<i32> = HashSet::with_hasher(hasher);
Expand Down Expand Up @@ -2497,8 +2498,8 @@ fn assert_covariance() {

#[cfg(test)]
mod test_set {
use super::super::map::DefaultHashBuilder;
use super::HashSet;
use crate::DefaultHashBuilder;
use std::vec::Vec;

#[test]
Expand Down
Loading

0 comments on commit e2b6b85

Please sign in to comment.