use std::{
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
};
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ValueFingerprint(u64);
impl ValueFingerprint {
#[must_use]
pub const fn new(value: u64) -> Self {
Self(value)
}
#[must_use]
pub const fn get(self) -> u64 {
self.0
}
}
pub trait FingerprintValue {
fn incremental_fingerprint(&self) -> ValueFingerprint;
}
impl<T> FingerprintValue for T
where
T: Hash,
{
fn incremental_fingerprint(&self) -> ValueFingerprint {
let mut hasher = DefaultHasher::new();
self.hash(&mut hasher);
ValueFingerprint(hasher.finish())
}
}