Skip to main content

luaur_vm/functions/
hashpointer.rs

1use crate::type_aliases::lua_node::LuaNode;
2use crate::type_aliases::lua_table::LuaTable;
3
4#[allow(non_snake_case)]
5pub unsafe fn hashpointer(t: *const LuaTable, p: *const core::ffi::c_void) -> *mut LuaNode {
6    // Discard high 32-bit portion on 64-bit platforms as it doesn't carry much entropy.
7    let mut h: u32 = (p as usize) as u32;
8
9    // MurmurHash3 32-bit finalizer
10    h ^= h >> 16;
11    h = h.wrapping_mul(0x85eb_ca6b_u32);
12    h ^= h >> 13;
13    h = h.wrapping_mul(0xc2b2_ae35_u32);
14    h ^= h >> 16;
15
16    crate::macros::gnode::gnode!(
17        t,
18        crate::macros::lmod::lmod!(h as i32, crate::macros::sizenode::sizenode!(t)) as usize
19    )
20}