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)]
14pub struct ValueFingerprint(u64);
15
16impl ValueFingerprint {
17 #[must_use]
19 pub const fn new(value: u64) -> Self {
20 Self(value)
21 }
22
23 #[must_use]
25 pub const fn get(self) -> u64 {
26 self.0
27 }
28}
29
30pub trait FingerprintValue {
32 fn incremental_fingerprint(&self) -> ValueFingerprint;
34}
35
36impl<T> FingerprintValue for T
37where
38 T: Hash,
39{
40 fn incremental_fingerprint(&self) -> ValueFingerprint {
41 let mut hasher = DefaultHasher::new();
42 self.hash(&mut hasher);
43 ValueFingerprint(hasher.finish())
44 }
45}