pub use seahash::{hash as hash64, hash_seeded as hash64_with_seeds, SeaHasher as Hasher64};
use crate::hasher::{FastHash, FastHasher, StreamHasher};
#[derive(Clone, Default)]
pub struct Hash64;
impl FastHash for Hash64 {
type Hash = u64;
type Seed = (u64, u64, u64, u64);
#[inline(always)]
fn hash<T: AsRef<[u8]>>(bytes: T) -> u64 {
seahash::hash(bytes.as_ref())
}
#[inline(always)]
fn hash_with_seed<T: AsRef<[u8]>>(bytes: T, seed: (u64, u64, u64, u64)) -> u64 {
seahash::hash_seeded(bytes.as_ref(), seed.0, seed.1, seed.2, seed.3)
}
}
impl_build_hasher!(Hasher64, Hash64);
impl FastHasher for Hasher64 {
type Seed = (u64, u64, u64, u64);
type Output = u64;
#[inline(always)]
fn new() -> Self {
Hasher64::new()
}
#[inline(always)]
fn with_seed(seed: Self::Seed) -> Self {
Hasher64::with_seeds(seed.0, seed.1, seed.2, seed.3)
}
}
impl StreamHasher for Hasher64 {}
#[cfg(test)]
mod tests {
use std::hash::Hasher;
use super::Hasher64;
#[test]
fn test_seahash64() {
let mut h = Hasher64::new();
h.write(b"hello");
assert_eq!(h.finish(), 153251464476911497);
h.write(b"world");
assert_eq!(h.finish(), 9532038143498849405);
}
}