rustc_hir/
def_path_hash_map.rs

1use rustc_hashes::Hash64;
2use rustc_span::def_id::DefIndex;
3
4#[derive(Clone, Default)]
5pub struct Config;
6
7impl odht::Config for Config {
8    // This hash-map is single-crate, so we only need to key by the local hash.
9    type Key = Hash64;
10    type Value = DefIndex;
11
12    type EncodedKey = [u8; 8];
13    type EncodedValue = [u8; 4];
14
15    type H = odht::UnHashFn;
16
17    #[inline]
18    fn encode_key(k: &Hash64) -> [u8; 8] {
19        k.as_u64().to_le_bytes()
20    }
21
22    #[inline]
23    fn encode_value(v: &DefIndex) -> [u8; 4] {
24        v.as_u32().to_le_bytes()
25    }
26
27    #[inline]
28    fn decode_key(k: &[u8; 8]) -> Hash64 {
29        Hash64::new(u64::from_le_bytes(*k))
30    }
31
32    #[inline]
33    fn decode_value(v: &[u8; 4]) -> DefIndex {
34        DefIndex::from_u32(u32::from_le_bytes(*v))
35    }
36}
37
38pub type DefPathHashMap = odht::HashTableOwned<Config>;