allow_core/
fingerprint.rs1pub fn normalize_snippet(input: &str) -> String {
2 input.split_whitespace().collect::<Vec<_>>().join(" ")
3}
4
5pub fn stable_hash_hex(input: &str) -> String {
6 let mut hash: u64 = 0xcbf29ce484222325;
8 for byte in input.as_bytes() {
9 hash ^= u64::from(*byte);
10 hash = hash.wrapping_mul(0x100000001b3);
11 }
12 format!("fnv1a64:{hash:016x}")
13}
14
15pub fn maybe_line_distance_score(hint: Option<u32>, actual: Option<u32>) -> u32 {
16 match (hint, actual) {
17 (Some(h), Some(a)) => {
18 let diff = h.abs_diff(a);
19 if diff == 0 {
20 15
21 } else if diff <= 3 {
22 12
23 } else if diff <= 10 {
24 8
25 } else if diff <= 25 {
26 3
27 } else {
28 0
29 }
30 }
31 _ => 0,
32 }
33}