1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use phf_shared;
pub const DYNAMIC_TAG: u8 = 0b_00;
pub const INLINE_TAG: u8 = 0b_01;
pub const STATIC_TAG: u8 = 0b_10;
pub const TAG_MASK: u64 = 0b_11;
pub const ENTRY_ALIGNMENT: usize = 4;
pub const MAX_INLINE_LEN: usize = 7;
pub const STATIC_SHIFT_BITS: usize = 32;
pub fn pack_static(n: u32) -> u64 {
(STATIC_TAG as u64) | ((n as u64) << STATIC_SHIFT_BITS)
}
pub struct StaticAtomSet {
pub key: u64,
pub disps: &'static [(u32, u32)],
pub atoms: &'static [&'static str],
}
impl StaticAtomSet {
#[inline]
pub fn get_index_or_hash(&self, s: &str) -> Result<u32, u64> {
let hash = phf_shared::hash(s, self.key);
let index = phf_shared::get_index(hash, self.disps, self.atoms.len());
if self.atoms[index as usize] == s {
Ok(index)
} else {
Err(hash)
}
}
#[inline]
pub fn index(&self, i: u32) -> Option<&'static str> {
self.atoms.get(i as usize).map(|&s| s)
}
#[inline]
pub fn iter(&self) -> ::std::slice::Iter<&'static str> {
self.atoms.iter()
}
}