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// ```
10// use solverforge_scoring::constraint::shared::compute_hash;
11//
12// let hash1 = compute_hash(&42);
13// let hash2 = compute_hash(&42);
14// assert_eq!(hash1, hash2);
15//
16// let hash3 = compute_hash(&43);
17// assert_ne!(hash1, hash3);
18// ```
19#[inline]
20pub fn compute_hash<T: Hash>(value: &T) -> u64 {
21 let mut hasher = std::collections::hash_map::DefaultHasher::new();
22 value.hash(&mut hasher);
23 hasher.finish()
24}