Skip to content

Commit 3b36034

Browse files
authored
Merge pull request #66 from apasel422/update
Rename `_hash_state` methods and add `hasher` method
2 parents a4bc197 + b295099 commit 3b36034

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/lib.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
156156
}
157157
}
158158

159-
/// Creates an empty linked hash map with the given initial hash state.
160-
pub fn with_hash_state(hash_state: S) -> Self {
161-
Self::with_map(HashMap::with_hasher(hash_state))
159+
/// Creates an empty linked hash map with the given initial hash builder.
160+
pub fn with_hasher(hash_builder: S) -> Self {
161+
Self::with_map(HashMap::with_hasher(hash_builder))
162162
}
163163

164-
/// Creates an empty linked hash map with the given initial capacity and hash state.
165-
pub fn with_capacity_and_hash_state(capacity: usize, hash_state: S) -> Self {
166-
Self::with_map(HashMap::with_capacity_and_hasher(capacity, hash_state))
164+
/// Creates an empty linked hash map with the given initial capacity and hash builder.
165+
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self {
166+
Self::with_map(HashMap::with_capacity_and_hasher(capacity, hash_builder))
167167
}
168168

169169
/// Reserves capacity for at least `additional` more elements to be inserted into the map. The
@@ -467,6 +467,11 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
467467
/// Returns whether the map is currently empty.
468468
pub fn is_empty(&self) -> bool { self.len() == 0 }
469469

470+
/// Returns a reference to the map's hasher.
471+
pub fn hasher(&self) -> &S {
472+
self.map.hasher()
473+
}
474+
470475
/// Clears the map of all key-value pairs.
471476
pub fn clear(&mut self) {
472477
self.map.clear();
@@ -629,18 +634,18 @@ impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
629634

630635
impl<K: Hash + Eq + Clone, V: Clone, S: BuildHasher + Clone> Clone for LinkedHashMap<K, V, S> {
631636
fn clone(&self) -> Self {
632-
let mut map = Self::with_hash_state(self.map.hasher().clone());
637+
let mut map = Self::with_hasher(self.map.hasher().clone());
633638
map.extend(self.iter().map(|(k, v)| (k.clone(), v.clone())));
634639
map
635640
}
636641
}
637642

638643
impl<K: Hash + Eq, V, S: BuildHasher + Default> Default for LinkedHashMap<K, V, S> {
639-
fn default() -> Self { LinkedHashMap::with_hash_state(Default::default()) }
644+
fn default() -> Self { Self::with_hasher(S::default()) }
640645
}
641646

642647
impl<K: Hash + Eq, V, S: BuildHasher> Extend<(K, V)> for LinkedHashMap<K, V, S> {
643-
fn extend<T: IntoIterator<Item=(K, V)>>(&mut self, iter: T) {
648+
fn extend<I: IntoIterator<Item=(K, V)>>(&mut self, iter: I) {
644649
for (k, v) in iter {
645650
self.insert(k, v);
646651
}
@@ -660,7 +665,7 @@ impl<'a, K, V, S> Extend<(&'a K, &'a V)> for LinkedHashMap<K, V, S>
660665
impl<K: Hash + Eq, V, S: BuildHasher + Default> iter::FromIterator<(K, V)> for LinkedHashMap<K, V, S> {
661666
fn from_iter<I: IntoIterator<Item=(K, V)>>(iter: I) -> Self {
662667
let iter = iter.into_iter();
663-
let mut map = Self::with_capacity_and_hash_state(iter.size_hint().0, Default::default());
668+
let mut map = Self::with_capacity_and_hasher(iter.size_hint().0, S::default());
664669
map.extend(iter);
665670
map
666671
}

0 commit comments

Comments
 (0)