Skip to content

Commit 7965258

Browse files
committed
Replace deprecated HashState with BuildHasher
Closes #38.
1 parent 0364ea2 commit 7965258

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/lib.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@
2828
//! ```
2929
3030
#![forbid(missing_docs)]
31-
#![feature(hashmap_hasher)]
3231
#![cfg_attr(test, feature(test))]
3332

3433
use std::borrow::Borrow;
3534
use std::cmp::Ordering;
3635
use std::collections::hash_map::{self, HashMap};
37-
use std::collections::hash_state::HashState;
3836
use std::fmt;
39-
use std::hash::{Hash, Hasher};
37+
use std::hash::{BuildHasher, Hash, Hasher};
4038
use std::iter;
4139
use std::marker;
4240
use std::mem;
@@ -131,7 +129,7 @@ impl<K, V, S> LinkedHashMap<K, V, S> {
131129
}
132130
}
133131

134-
impl<K: Hash + Eq, V, S: HashState> LinkedHashMap<K, V, S> {
132+
impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
135133
fn with_map(map: HashMap<KeyRef<K>, Box<LinkedHashMapEntry<K, V>>, S>) -> Self {
136134
LinkedHashMap {
137135
map: map,
@@ -142,12 +140,12 @@ impl<K: Hash + Eq, V, S: HashState> LinkedHashMap<K, V, S> {
142140

143141
/// Creates an empty linked hash map with the given initial hash state.
144142
pub fn with_hash_state(hash_state: S) -> Self {
145-
Self::with_map(HashMap::with_hash_state(hash_state))
143+
Self::with_map(HashMap::with_hasher(hash_state))
146144
}
147145

148146
/// Creates an empty linked hash map with the given initial capacity and hash state.
149147
pub fn with_capacity_and_hash_state(capacity: usize, hash_state: S) -> Self {
150-
Self::with_map(HashMap::with_capacity_and_hash_state(capacity, hash_state))
148+
Self::with_map(HashMap::with_capacity_and_hasher(capacity, hash_state))
151149
}
152150

153151
/// Reserves capacity for at least `additional` more elements to be inserted into the map. The
@@ -576,7 +574,7 @@ impl<K: Hash + Eq, V, S: HashState> LinkedHashMap<K, V, S> {
576574
}
577575

578576
impl<'a, K, V, S, Q: ?Sized> Index<&'a Q> for LinkedHashMap<K, V, S>
579-
where K: Hash + Eq + Borrow<Q>, S: HashState, Q: Eq + Hash
577+
where K: Hash + Eq + Borrow<Q>, S: BuildHasher, Q: Eq + Hash
580578
{
581579
type Output = V;
582580

@@ -586,14 +584,14 @@ impl<'a, K, V, S, Q: ?Sized> Index<&'a Q> for LinkedHashMap<K, V, S>
586584
}
587585

588586
impl<'a, K, V, S, Q: ?Sized> IndexMut<&'a Q> for LinkedHashMap<K, V, S>
589-
where K: Hash + Eq + Borrow<Q>, S: HashState, Q: Eq + Hash
587+
where K: Hash + Eq + Borrow<Q>, S: BuildHasher, Q: Eq + Hash
590588
{
591589
fn index_mut(&mut self, index: &'a Q) -> &mut V {
592590
self.get_mut(index).expect("no entry found for key")
593591
}
594592
}
595593

596-
impl<K: Hash + Eq, V, S: HashState> LinkedHashMap<K, V, S> {
594+
impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S> {
597595
#[inline]
598596
fn detach(&mut self, node: *mut LinkedHashMapEntry<K, V>) {
599597
unsafe {
@@ -622,19 +620,19 @@ impl<K: Hash + Eq + Clone, V: Clone> Clone for LinkedHashMap<K, V> {
622620
}
623621
}
624622

625-
impl<K: Hash + Eq, V, S: HashState + Default> Default for LinkedHashMap<K, V, S> {
623+
impl<K: Hash + Eq, V, S: BuildHasher + Default> Default for LinkedHashMap<K, V, S> {
626624
fn default() -> Self { LinkedHashMap::with_hash_state(Default::default()) }
627625
}
628626

629-
impl<K: Hash + Eq, V, S: HashState> Extend<(K, V)> for LinkedHashMap<K, V, S> {
627+
impl<K: Hash + Eq, V, S: BuildHasher> Extend<(K, V)> for LinkedHashMap<K, V, S> {
630628
fn extend<T: IntoIterator<Item=(K, V)>>(&mut self, iter: T) {
631629
for (k, v) in iter {
632630
self.insert(k, v);
633631
}
634632
}
635633
}
636634

637-
impl<K: Hash + Eq, V, S: HashState + Default> iter::FromIterator<(K, V)> for LinkedHashMap<K, V, S> {
635+
impl<K: Hash + Eq, V, S: BuildHasher + Default> iter::FromIterator<(K, V)> for LinkedHashMap<K, V, S> {
638636
fn from_iter<I: IntoIterator<Item=(K, V)>>(iter: I) -> Self {
639637
let iter = iter.into_iter();
640638
let mut map = Self::with_capacity_and_hash_state(iter.size_hint().0, Default::default());
@@ -643,14 +641,14 @@ impl<K: Hash + Eq, V, S: HashState + Default> iter::FromIterator<(K, V)> for Lin
643641
}
644642
}
645643

646-
impl<A: fmt::Debug + Hash + Eq, B: fmt::Debug, S: HashState> fmt::Debug for LinkedHashMap<A, B, S> {
644+
impl<A: fmt::Debug + Hash + Eq, B: fmt::Debug, S: BuildHasher> fmt::Debug for LinkedHashMap<A, B, S> {
647645
/// Returns a string that lists the key-value pairs in insertion order.
648646
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
649647
f.debug_map().entries(self).finish()
650648
}
651649
}
652650

653-
impl<K: Hash + Eq, V: PartialEq, S: HashState> PartialEq for LinkedHashMap<K, V, S> {
651+
impl<K: Hash + Eq, V: PartialEq, S: BuildHasher> PartialEq for LinkedHashMap<K, V, S> {
654652
fn eq(&self, other: &Self) -> bool {
655653
self.len() == other.len() && self.iter().eq(other)
656654
}
@@ -660,9 +658,9 @@ impl<K: Hash + Eq, V: PartialEq, S: HashState> PartialEq for LinkedHashMap<K, V,
660658
}
661659
}
662660

663-
impl<K: Hash + Eq, V: Eq, S: HashState> Eq for LinkedHashMap<K, V, S> {}
661+
impl<K: Hash + Eq, V: Eq, S: BuildHasher> Eq for LinkedHashMap<K, V, S> {}
664662

665-
impl<K: Hash + Eq + PartialOrd, V: PartialOrd, S: HashState> PartialOrd for LinkedHashMap<K, V, S> {
663+
impl<K: Hash + Eq + PartialOrd, V: PartialOrd, S: BuildHasher> PartialOrd for LinkedHashMap<K, V, S> {
666664
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
667665
self.iter().partial_cmp(other)
668666
}
@@ -684,13 +682,13 @@ impl<K: Hash + Eq + PartialOrd, V: PartialOrd, S: HashState> PartialOrd for Link
684682
}
685683
}
686684

687-
impl<K: Hash + Eq + Ord, V: Ord, S: HashState> Ord for LinkedHashMap<K, V, S> {
685+
impl<K: Hash + Eq + Ord, V: Ord, S: BuildHasher> Ord for LinkedHashMap<K, V, S> {
688686
fn cmp(&self, other: &Self) -> Ordering {
689687
self.iter().cmp(other)
690688
}
691689
}
692690

693-
impl<K: Hash + Eq, V: Hash, S: HashState> Hash for LinkedHashMap<K, V, S> {
691+
impl<K: Hash + Eq, V: Hash, S: BuildHasher> Hash for LinkedHashMap<K, V, S> {
694692
fn hash<H: Hasher>(&self, h: &mut H) { for e in self.iter() { e.hash(h); } }
695693
}
696694

@@ -867,13 +865,13 @@ impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {
867865
fn len(&self) -> usize { self.inner.len() }
868866
}
869867

870-
impl<'a, K: Hash + Eq, V, S: HashState> IntoIterator for &'a LinkedHashMap<K, V, S> {
868+
impl<'a, K: Hash + Eq, V, S: BuildHasher> IntoIterator for &'a LinkedHashMap<K, V, S> {
871869
type Item = (&'a K, &'a V);
872870
type IntoIter = Iter<'a, K, V>;
873871
fn into_iter(self) -> Iter<'a, K, V> { self.iter() }
874872
}
875873

876-
impl<'a, K: Hash + Eq, V, S: HashState> IntoIterator for &'a mut LinkedHashMap<K, V, S> {
874+
impl<'a, K: Hash + Eq, V, S: BuildHasher> IntoIterator for &'a mut LinkedHashMap<K, V, S> {
877875
type Item = (&'a K, &'a mut V);
878876
type IntoIter = IterMut<'a, K, V>;
879877
fn into_iter(self) -> IterMut<'a, K, V> { self.iter_mut() }

0 commit comments

Comments
 (0)