luaur_bytecode/methods/
bc_op_hash_operator_call.rs1use crate::records::bc_op::BcOp;
2use crate::records::bc_op_hash::BcOpHash;
3use core::hash::{Hash, Hasher};
4use luaur_common::records::dense_hash_table::DenseHasher;
5
6impl BcOpHash {
7 pub fn operator_call(&self, p: &BcOp) -> usize {
8 let mut res: usize = 0;
9 let size = core::mem::size_of::<BcOp>().min(core::mem::size_of::<usize>());
10 unsafe {
11 core::ptr::copy_nonoverlapping(
12 p as *const BcOp as *const u8,
13 &mut res as *mut usize as *mut u8,
14 size,
15 );
16 }
17 res
18 }
19}
20
21impl std::hash::BuildHasher for BcOpHash {
22 type Hasher = std::collections::hash_map::DefaultHasher;
23 fn build_hasher(&self) -> Self::Hasher {
24 std::collections::hash_map::DefaultHasher::new()
25 }
26}
27
28impl DenseHasher<BcOp> for BcOpHash {
29 fn hash(&self, key: &BcOp) -> usize {
30 self.operator_call(key)
31 }
32}