1 use std::collections::{HashMap, HashSet}; 2 use std::hash::{BuildHasherDefault, Hasher}; 3 4 pub type UnhashMap<K, V> = HashMap<K, V, BuildHasherDefault<Unhasher>>; 5 pub type UnhashSet<V> = HashSet<V, BuildHasherDefault<Unhasher>>; 6 7 /// This no-op hasher expects only a single `write_u64` call. It's intended for 8 /// map keys that already have hash-like quality, like `Fingerprint`. 9 #[derive(Default)] 10 pub struct Unhasher { 11 value: u64, 12 } 13 14 impl Hasher for Unhasher { 15 #[inline] finish(&self) -> u6416 fn finish(&self) -> u64 { 17 self.value 18 } 19 write(&mut self, _bytes: &[u8])20 fn write(&mut self, _bytes: &[u8]) { 21 unimplemented!("use write_u64"); 22 } 23 24 #[inline] write_u64(&mut self, value: u64)25 fn write_u64(&mut self, value: u64) { 26 debug_assert_eq!(0, self.value, "Unhasher doesn't mix values!"); 27 self.value = value; 28 } 29 } 30