luaur_code_gen/records/
constant_key_hash.rs1use crate::records::constant_key::ConstantKey;
2
3#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
4#[repr(C)]
5pub struct ConstantKeyHash;
6
7impl ConstantKeyHash {
8 pub fn call(&self, key: &ConstantKey) -> usize {
9 let m: u32 = 0x5bd1e995;
10
11 let mut h1 = key.value as u32;
12 let mut h2 = (key.value >> 32) as u32 ^ ((key.kind as i32 as u32).wrapping_mul(m));
13
14 h1 ^= h2 >> 18;
15 h1 = h1.wrapping_mul(m);
16 h2 ^= h1 >> 22;
17 h2 = h2.wrapping_mul(m);
18 h1 ^= h2 >> 17;
19 h1 = h1.wrapping_mul(m);
20 h2 ^= h1 >> 19;
21 h2 = h2.wrapping_mul(m);
22
23 h2 as usize
24 }
25}
26
27#[allow(non_snake_case)]
28pub fn ir_builder_constant_key_hash_operator_call(
29 this: &ConstantKeyHash,
30 key: &ConstantKey,
31) -> usize {
32 this.call(key)
33}