diff --git a/src/fnv.rs b/src/fnv.rs new file mode 100644 index 0000000..12d7873 --- /dev/null +++ b/src/fnv.rs @@ -0,0 +1,15 @@ +#[inline(always)] +pub fn fnv_hash(prime: u32, initial_value: u32, data: &[u16]) -> u32 { + let mut hash: u32 = initial_value; + if data.len() == 0 { + return hash; + } + for element in data { + hash = (*element as u32 ^ hash).wrapping_mul(prime); + } + hash +} + +pub fn ue_gas_fnv_hash(data: &[u16]) -> u32 { + fnv_hash(0x1000193, 0x0, data) +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index bb9b974..161825e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,4 +7,5 @@ pub trait Add { } pub mod t_array; -pub mod f_string; \ No newline at end of file +pub mod f_string; +pub mod fnv; \ No newline at end of file