use std::hash::{Hash, Hasher};
use std::sync::atomic::{AtomicU64, Ordering};
pub(crate) struct StableHasher(u64);
impl StableHasher {
pub(crate) fn new() -> Self {
Self(14695981039346656037)
}
}
impl Hasher for StableHasher {
fn finish(&self) -> u64 {
self.0
}
fn write(&mut self, bytes: &[u8]) {
for &b in bytes {
self.0 ^= b as u64;
self.0 = self.0.wrapping_mul(1099511628211);
}
}
}
pub(crate) fn hash_value(v: impl Hash) -> u64 {
let mut h = StableHasher::new();
v.hash(&mut h);
h.finish()
}
pub(crate) fn tick() -> u64 {
static COUNTER: AtomicU64 = AtomicU64::new(1);
COUNTER.fetch_add(1, Ordering::Relaxed)
}