use std::hash::BuildHasher;
const STATE: ahash::RandomState = ahash::RandomState::with_seeds(
0x243f_6a88_85a3_08d3,
0x1319_8a2e_0370_7344,
0xa409_3822_299f_31d0,
0x082e_fa98_ec4e_6c89,
);
#[derive(Debug, Clone, Copy, Default)]
pub struct HashState;
impl BuildHasher for HashState {
type Hasher = ahash::AHasher;
fn build_hasher(&self) -> Self::Hasher {
STATE.build_hasher()
}
}
pub type HashMap<K, V> = std::collections::HashMap<K, V, HashState>;
pub type HashSet<T> = std::collections::HashSet<T, HashState>;
#[cfg(test)]
mod tests {
use super::*;
use std::process::Command;
const PROBE: &str = "SKIF_HASH_PROBE";
#[test]
fn hashes_are_the_same_in_every_process() {
let local = HashState.hash_one("skif");
if std::env::var_os(PROBE).is_some() {
println!("probe={local}");
return;
}
let output = Command::new(std::env::current_exe().unwrap())
.args([
"--exact",
"hash::tests::hashes_are_the_same_in_every_process",
"--nocapture",
])
.env(PROBE, "1")
.output()
.unwrap();
let stdout = String::from_utf8_lossy(&output.stdout);
let probed = stdout.lines().find_map(|line| line.strip_prefix("probe=")).unwrap();
assert_eq!(probed, local.to_string());
}
}