state/ident_hash.rs
1use std::hash::Hasher;
2
3// This is a _super_ stupid hash. It just uses its input as the hash value. This
4// hash is meant to be used _only_ for "prehashed" values. In particular, we use
5// this so that hashing a TypeId is essentially a noop. This is because TypeIds
6// are already unique integers.
7#[derive(Default)]
8pub struct IdentHash(u64);
9
10impl Hasher for IdentHash {
11 fn finish(&self) -> u64 {
12 self.0
13 }
14
15 fn write(&mut self, bytes: &[u8]) {
16 for byte in bytes {
17 self.write_u8(*byte);
18 }
19 }
20
21 fn write_u8(&mut self, i: u8) {
22 self.0 = (self.0 << 8) | (i as u64);
23 }
24
25 fn write_u64(&mut self, i: u64) {
26 self.0 = i;
27 }
28}