use std::hash::Hasher;
use twox_hash::{XxHash3_128, XxHash64};
pub type HashFn<H> = fn(&[u8]) -> H;
pub fn hash64(key: &[u8]) -> u64 {
let mut hasher = XxHash64::with_seed(0);
hasher.write(key);
hasher.finish()
}
pub fn hash128(key: &[u8]) -> u128 {
XxHash3_128::oneshot(key)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hash64_is_deterministic() {
assert_eq!(hash64(b"hello"), hash64(b"hello"));
assert_ne!(hash64(b"hello"), hash64(b"world"));
}
#[test]
fn hash64_empty_input_is_defined() {
assert_eq!(hash64(b""), hash64(b""));
}
#[test]
fn hash128_is_deterministic() {
assert_eq!(hash128(b"hello"), hash128(b"hello"));
assert_ne!(hash128(b"hello"), hash128(b"world"));
}
#[test]
fn hash128_empty_input_is_defined() {
assert_eq!(hash128(b""), hash128(b""));
}
}