Added FNV functionalities

This commit is contained in:
xavo95 2025-01-24 01:09:41 +01:00
parent f4043b9cd0
commit dde535bafb
Signed by: xavo95
GPG key ID: CBF8ADED6DEBB783
2 changed files with 17 additions and 1 deletions

15
src/fnv.rs Normal file
View file

@ -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)
}

View file

@ -8,3 +8,4 @@ pub trait Add<T = Self> {
pub mod t_array; pub mod t_array;
pub mod f_string; pub mod f_string;
pub mod fnv;