]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_data_structures/src/unhash.rs
Rollup merge of #93580 - m-ou-se:stabilize-pin-static-ref, r=scottmcm
[rust.git] / compiler / rustc_data_structures / src / unhash.rs
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]
16     fn finish(&self) -> u64 {
17         self.value
18     }
19
20     fn write(&mut self, _bytes: &[u8]) {
21         unimplemented!("use write_u64");
22     }
23
24     #[inline]
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 }