Skip to content

Commit

Permalink
Bumped version (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchellBerend authored Feb 6, 2024
1 parent b5f1c38 commit 6ae1b8c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "defaultdict"
version = "0.17.0"
version = "0.18.0"
description = "A hashmap implementation that mirrors the python defaultdict."
edition = "2021"
authors = ["Mitchell Berendhuysen"]
Expand Down
58 changes: 29 additions & 29 deletions src/default_hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,6 @@ where
V: Default,
S: BuildHasher,
{
/// Creates an empty [`DefaultHashMap`] which will use the given hash builder to hash
/// keys.
///
/// Warning: `hash_builder` is normally randomly generated, and
/// is designed to allow HashMaps to be resistant to attacks that
/// cause many collisions and very poor performance. Setting it
/// manually using this function can expose a DoS attack vector.
///
/// The `hash_builder` passed should implement the [`BuildHasher`] trait for
/// the HashMap to be useful, see its documentation for details.
///
/// # Examples
///
/// ```
/// use defaultdict::DefaultHashMap;
/// use std::collections::hash_map::RandomState;
///
/// let s = RandomState::new();
/// let mut map = DefaultHashMap::with_hasher(s);
/// map.insert(1, 2);
/// ```
#[inline]
pub fn with_hasher(hash_builder: S) -> Self {
DefaultHashMap {
_inner: HashMap::with_hasher(hash_builder),
_default: V::default(),
}
}

/// Returns the number of elements the map can hold without reallocating.
///
/// This number is a lower bound; the `HashMap<K, V>` might be able to hold more, but is
Expand Down Expand Up @@ -540,6 +511,35 @@ where
pub fn values_mut(&mut self) -> ValuesMut<K, V> {
self._inner.values_mut()
}

/// Creates an empty [`DefaultHashMap`] which will use the given hash builder to hash
/// keys.
///
/// Warning: `hash_builder` is normally randomly generated, and
/// is designed to allow HashMaps to be resistant to attacks that
/// cause many collisions and very poor performance. Setting it
/// manually using this function can expose a DoS attack vector.
///
/// The `hash_builder` passed should implement the [`BuildHasher`] trait for
/// the HashMap to be useful, see its documentation for details.
///
/// # Examples
///
/// ```
/// use defaultdict::DefaultHashMap;
/// use std::collections::hash_map::RandomState;
///
/// let s = RandomState::new();
/// let mut map = DefaultHashMap::with_hasher(s);
/// map.insert(1, 2);
/// ```
#[inline]
pub fn with_hasher(hash_builder: S) -> Self {
DefaultHashMap {
_inner: HashMap::with_hasher(hash_builder),
_default: V::default(),
}
}
}

impl<K, V> Default for DefaultHashMap<K, V>
Expand Down

0 comments on commit 6ae1b8c

Please sign in to comment.