Skip to content

Commit

Permalink
feat: const with_hasher (#168)
Browse files Browse the repository at this point in the history
* feat: const `with_hasher`

* loom fix and `HashSet`
  • Loading branch information
Daniel-Aaron-Bloom authored Nov 15, 2024
1 parent 2b7c38f commit 7dc282c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ where
///
/// let hashmap: HashMap<u64, u32, RandomState> = HashMap::with_hasher(RandomState::new());
/// ```
#[cfg(not(feature = "loom"))]
#[inline]
pub const fn with_hasher(build_hasher: H) -> Self {
Self {
array: AtomicShared::null(),
minimum_capacity: AtomicUsize::new(0),
build_hasher,
}
}

/// Creates an empty [`HashMap`] with the given [`BuildHasher`].
#[cfg(feature = "loom")]
#[inline]
pub fn with_hasher(build_hasher: H) -> Self {
Self {
Expand Down
10 changes: 10 additions & 0 deletions src/hash_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ where
///
/// let hashset: HashSet<u64, RandomState> = 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 {
Expand Down

0 comments on commit 7dc282c

Please sign in to comment.