mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-09 13:07:41 +00:00
all_within hasher: mix the high bits into the low ones (#5463)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
bflatastic
co-authored by
Claude Sonnet 5.5
parent
f4ba106e39
commit
6ede10de4d
@@ -337,7 +337,8 @@ impl Hasher for CellHasher {
|
||||
}
|
||||
|
||||
fn finish(&self) -> u64 {
|
||||
self.0
|
||||
// The table picks its bucket from the low bits, which a product leaves weak: bring the strong high bits down.
|
||||
self.0.rotate_left(26)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,4 +479,14 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cell_hasher_spreads_keys_whose_low_bits_are_zero() {
|
||||
use std::hash::BuildHasher;
|
||||
// Cell indices that are all multiples of 1024 (pixel-exact points with a power-of-two limit).
|
||||
let build = BuildHasherDefault::<CellHasher>::default();
|
||||
let buckets: std::collections::HashSet<u64> =
|
||||
(0..64i64).flat_map(|i| (0..64i64).map(move |j| (i << 10, j << 10))).map(|k| build.hash_one(k) & 1023).collect();
|
||||
assert!(buckets.len() > 600, "{} of 1024 buckets used", buckets.len());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user