From c13a8aea4615ab194587e904e83c4b9301a135fe Mon Sep 17 00:00:00 2001 From: Daniel Bloom <7810950-Daniel.Aaron.Bloom@users.noreply.gitlab.com> Date: Thu, 14 Nov 2024 09:36:50 -0800 Subject: [PATCH 1/2] feat: const `with_hasher` --- src/hash_map.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hash_map.rs b/src/hash_map.rs index 4044e6a..7ed74e7 100644 --- a/src/hash_map.rs +++ b/src/hash_map.rs @@ -131,7 +131,7 @@ where /// let hashmap: HashMap = HashMap::with_hasher(RandomState::new()); /// ``` #[inline] - pub fn with_hasher(build_hasher: H) -> Self { + pub const fn with_hasher(build_hasher: H) -> Self { Self { array: AtomicShared::null(), minimum_capacity: AtomicUsize::new(0), From 84c11b453cb571230d820f504655a5ee11226d29 Mon Sep 17 00:00:00 2001 From: Daniel Bloom <7810950-Daniel.Aaron.Bloom@users.noreply.gitlab.com> Date: Thu, 14 Nov 2024 12:15:53 -0800 Subject: [PATCH 2/2] loom fix and `HashSet` --- src/hash_map.rs | 12 ++++++++++++ src/hash_set.rs | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/hash_map.rs b/src/hash_map.rs index 7ed74e7..5316829 100644 --- a/src/hash_map.rs +++ b/src/hash_map.rs @@ -130,6 +130,7 @@ where /// /// let hashmap: HashMap = HashMap::with_hasher(RandomState::new()); /// ``` + #[cfg(not(feature = "loom"))] #[inline] pub const fn with_hasher(build_hasher: H) -> Self { Self { @@ -139,6 +140,17 @@ where } } + /// Creates an empty [`HashMap`] with the given [`BuildHasher`]. + #[cfg(feature = "loom")] + #[inline] + pub fn with_hasher(build_hasher: H) -> Self { + Self { + array: AtomicShared::null(), + minimum_capacity: AtomicUsize::new(0), + build_hasher, + } + } + /// Creates an empty [`HashMap`] with the specified capacity and [`BuildHasher`]. /// /// The actual capacity is equal to or greater than the specified capacity. diff --git a/src/hash_set.rs b/src/hash_set.rs index 58610cf..546707e 100644 --- a/src/hash_set.rs +++ b/src/hash_set.rs @@ -35,6 +35,16 @@ where /// /// let hashset: HashSet = HashSet::with_hasher(RandomState::new()); /// ``` + #[cfg(not(feature = "loom"))] + #[inline] + pub const fn with_hasher(build_hasher: H) -> Self { + Self { + map: HashMap::with_hasher(build_hasher), + } + } + + /// Creates an empty [`HashSet`] with the given [`BuildHasher`]. + #[cfg(feature = "loom")] #[inline] pub fn with_hasher(build_hasher: H) -> Self { Self {