use core::hash::{Hash, Hasher};
pub struct ProblemHash {
state: seahash::SeaHasher,
}
impl Default for ProblemHash {
fn default() -> Self {
Self::new()
}
}
impl ProblemHash {
#[must_use]
pub fn new() -> Self {
Self {
state: seahash::SeaHasher::new(),
}
}
pub fn hash<T: Hash>(&mut self, value: &T) {
value.hash(&mut self.state);
}
#[must_use]
pub fn finish(self) -> u64 {
self.state.finish()
}
}
impl Hasher for ProblemHash {
fn finish(&self) -> u64 {
self.state.finish()
}
fn write(&mut self, bytes: &[u8]) {
self.state.write(bytes);
}
}
#[allow(dead_code)]
#[must_use]
pub fn hash_problem<T: Hash>(problem: &T) -> u64 {
let mut hasher = ProblemHash::new();
problem.hash(&mut hasher);
hasher.finish()
}