Skip to content

Commit 7dc282c

Browse files
feat: const with_hasher (#168)
* feat: const `with_hasher` * loom fix and `HashSet`
1 parent 2b7c38f commit 7dc282c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/hash_map.rs

+12
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ where
130130
///
131131
/// let hashmap: HashMap<u64, u32, RandomState> = HashMap::with_hasher(RandomState::new());
132132
/// ```
133+
#[cfg(not(feature = "loom"))]
134+
#[inline]
135+
pub const fn with_hasher(build_hasher: H) -> Self {
136+
Self {
137+
array: AtomicShared::null(),
138+
minimum_capacity: AtomicUsize::new(0),
139+
build_hasher,
140+
}
141+
}
142+
143+
/// Creates an empty [`HashMap`] with the given [`BuildHasher`].
144+
#[cfg(feature = "loom")]
133145
#[inline]
134146
pub fn with_hasher(build_hasher: H) -> Self {
135147
Self {

src/hash_set.rs

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ where
3535
///
3636
/// let hashset: HashSet<u64, RandomState> = HashSet::with_hasher(RandomState::new());
3737
/// ```
38+
#[cfg(not(feature = "loom"))]
39+
#[inline]
40+
pub const fn with_hasher(build_hasher: H) -> Self {
41+
Self {
42+
map: HashMap::with_hasher(build_hasher),
43+
}
44+
}
45+
46+
/// Creates an empty [`HashSet`] with the given [`BuildHasher`].
47+
#[cfg(feature = "loom")]
3848
#[inline]
3949
pub fn with_hasher(build_hasher: H) -> Self {
4050
Self {

0 commit comments

Comments
 (0)