pub(crate) fn splitmix64(mut z: u64) -> u64 {
z = z.wrapping_add(0x9e37_79b9_7f4a_7c15);
z = (z ^ (z >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9);
z = (z ^ (z >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb);
z ^ (z >> 31)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn same_input_produces_same_output() {
assert_eq!(splitmix64(0), splitmix64(0));
assert_eq!(splitmix64(42), splitmix64(42));
assert_eq!(splitmix64(u64::MAX), splitmix64(u64::MAX));
}
#[test]
fn different_inputs_produce_different_outputs() {
let outputs: Vec<u64> = (0..1000).map(splitmix64).collect();
let mut deduped = outputs.clone();
deduped.sort_unstable();
deduped.dedup();
assert_eq!(
outputs.len(),
deduped.len(),
"1000 consecutive inputs must all produce distinct outputs"
);
}
#[test]
fn zero_input_does_not_produce_zero() {
assert_ne!(splitmix64(0), 0);
}
#[test]
fn max_input_does_not_panic() {
let _ = splitmix64(u64::MAX);
}
#[test]
fn known_output_regression_anchor() {
let result = splitmix64(0);
assert_eq!(
result, 16294208416658607535,
"splitmix64(0) must match the canonical SplitMix64 output"
);
}
#[test]
fn output_covers_full_bit_width() {
let mut any_high_set = false;
for i in 0..100 {
let out = splitmix64(i);
if out & 0xFFFF_FFFF_0000_0000 != 0 {
any_high_set = true;
break;
}
}
assert!(
any_high_set,
"at least one output in 0..100 must have high 32 bits set"
);
}
}