Added FNV functionalities
This commit is contained in:
parent
f4043b9cd0
commit
dde535bafb
2 changed files with 17 additions and 1 deletions
15
src/fnv.rs
Normal file
15
src/fnv.rs
Normal 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)
|
||||||
|
}
|
|
@ -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;
|
Loading…
Reference in a new issue