pub fn derive_seed(base: u64, i: usize) -> u64 {
base.wrapping_add((i as u64).wrapping_mul(0x9E37_79B9_7F4A_7C15))
}
pub fn topo_hash(topology_json: &str) -> String {
format!(
"{:016x}",
xxhash_rust::xxh3::xxh3_64(topology_json.as_bytes())
)
}
pub fn weight_seed(run_seed: u64) -> usize {
derive_seed(run_seed, WEIGHT_INIT_ORDINAL) as usize
}
const WEIGHT_INIT_ORDINAL: usize = usize::MAX / 2;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_deterministic() {
assert_eq!(derive_seed(42, 0), derive_seed(42, 0));
assert_eq!(derive_seed(42, 7), derive_seed(42, 7));
}
#[test]
fn spreads_indices_apart() {
assert_ne!(derive_seed(42, 0), derive_seed(42, 1));
assert_ne!(derive_seed(42, 1), derive_seed(42, 2));
assert_ne!(derive_seed(41, 0), derive_seed(42, 0));
}
}