sim_incremental_core/
fingerprint.rs1use std::{
4 collections::hash_map::DefaultHasher,
5 hash::{Hash, Hasher},
6};
7
8#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
10pub struct ValueFingerprint(u64);
11
12impl ValueFingerprint {
13 #[must_use]
15 pub const fn new(value: u64) -> Self {
16 Self(value)
17 }
18
19 #[must_use]
21 pub const fn get(self) -> u64 {
22 self.0
23 }
24}
25
26pub trait FingerprintValue {
28 fn incremental_fingerprint(&self) -> ValueFingerprint;
30}
31
32impl<T> FingerprintValue for T
33where
34 T: Hash,
35{
36 fn incremental_fingerprint(&self) -> ValueFingerprint {
37 let mut hasher = DefaultHasher::new();
38 self.hash(&mut hasher);
39 ValueFingerprint(hasher.finish())
40 }
41}