summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_data_structures/src/unhash.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /compiler/rustc_data_structures/src/unhash.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_data_structures/src/unhash.rs')
-rw-r--r--compiler/rustc_data_structures/src/unhash.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/unhash.rs b/compiler/rustc_data_structures/src/unhash.rs
new file mode 100644
index 000000000..48e21a9da
--- /dev/null
+++ b/compiler/rustc_data_structures/src/unhash.rs
@@ -0,0 +1,29 @@
+use std::collections::{HashMap, HashSet};
+use std::hash::{BuildHasherDefault, Hasher};
+
+pub type UnhashMap<K, V> = HashMap<K, V, BuildHasherDefault<Unhasher>>;
+pub type UnhashSet<V> = HashSet<V, BuildHasherDefault<Unhasher>>;
+
+/// This no-op hasher expects only a single `write_u64` call. It's intended for
+/// map keys that already have hash-like quality, like `Fingerprint`.
+#[derive(Default)]
+pub struct Unhasher {
+ value: u64,
+}
+
+impl Hasher for Unhasher {
+ #[inline]
+ fn finish(&self) -> u64 {
+ self.value
+ }
+
+ fn write(&mut self, _bytes: &[u8]) {
+ unimplemented!("use write_u64");
+ }
+
+ #[inline]
+ fn write_u64(&mut self, value: u64) {
+ debug_assert_eq!(0, self.value, "Unhasher doesn't mix values!");
+ self.value = value;
+ }
+}