Skip to main content

solverforge_scoring/constraint/
shared.rs

1// Shared utilities for typed constraints.
2
3use std::hash::{Hash, Hasher};
4
5/* Computes a hash of a value for tracking in join indices.
6
7# Example
8
9```
10use solverforge_scoring::constraint::shared::compute_hash;
11
12let hash1 = compute_hash(&42);
13let hash2 = compute_hash(&42);
14assert_eq!(hash1, hash2);
15
16let hash3 = compute_hash(&43);
17assert_ne!(hash1, hash3);
18```
19*/
20#[inline]
21pub fn compute_hash<T: Hash>(value: &T) -> u64 {
22    let mut hasher = std::collections::hash_map::DefaultHasher::new();
23    value.hash(&mut hasher);
24    hasher.finish()
25}