From 6ab38c5a337fc3a201bc7d5b0facd28f0127a936 Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Fri, 22 Nov 2024 11:41:05 +0100 Subject: [PATCH 1/3] get rid of Hash128::hash64 --- crates/store/re_log_types/src/hash.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/crates/store/re_log_types/src/hash.rs b/crates/store/re_log_types/src/hash.rs index 63be3694adb1..f3e66542b6a9 100644 --- a/crates/store/re_log_types/src/hash.rs +++ b/crates/store/re_log_types/src/hash.rs @@ -72,11 +72,6 @@ impl Hash128 { Self(double_hash(value)) } - #[inline] - pub fn hash64(&self) -> u64 { - self.0[0] - } - #[inline] pub fn first64(&self) -> u64 { self.0[0] From 87cca8e9cb05396fb6104ca4b5b000253388aa0c Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Fri, 22 Nov 2024 11:45:57 +0100 Subject: [PATCH 2/3] fix Hash128::hash --- crates/store/re_log_types/src/hash.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/store/re_log_types/src/hash.rs b/crates/store/re_log_types/src/hash.rs index f3e66542b6a9..cb6fbf2dd0ec 100644 --- a/crates/store/re_log_types/src/hash.rs +++ b/crates/store/re_log_types/src/hash.rs @@ -86,7 +86,7 @@ impl Hash128 { impl std::hash::Hash for Hash128 { #[inline] fn hash(&self, state: &mut H) { - state.write_u64(self.0[0]); + state.write_u128((self.first64() as u128) << 64 | self.second64() as u128); } } From 6930cfb7c757bf003414c254394b4473f019873f Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Fri, 22 Nov 2024 16:26:34 +0100 Subject: [PATCH 3/3] remove Hash128 --- crates/store/re_log_types/src/hash.rs | 68 --------------------------- 1 file changed, 68 deletions(-) diff --git a/crates/store/re_log_types/src/hash.rs b/crates/store/re_log_types/src/hash.rs index cb6fbf2dd0ec..93826b76edee 100644 --- a/crates/store/re_log_types/src/hash.rs +++ b/crates/store/re_log_types/src/hash.rs @@ -1,7 +1,3 @@ -// ---------------------------------------------------------------------------- - -use std::hash::BuildHasher; - /// 64-bit hash. /// /// 10^-12 collision risk with 6k values. @@ -61,72 +57,8 @@ impl std::fmt::Debug for Hash64 { // ---------------------------------------------------------------------------- -/// 128-bit hash. Negligible risk for collision. -#[derive(Copy, Clone, Eq)] -pub struct Hash128([u64; 2]); - -impl Hash128 { - pub const ZERO: Self = Self([0; 2]); - - pub fn hash(value: impl std::hash::Hash + Copy) -> Self { - Self(double_hash(value)) - } - - #[inline] - pub fn first64(&self) -> u64 { - self.0[0] - } - - #[inline] - pub fn second64(&self) -> u64 { - self.0[1] - } -} - -impl std::hash::Hash for Hash128 { - #[inline] - fn hash(&self, state: &mut H) { - state.write_u128((self.first64() as u128) << 64 | self.second64() as u128); - } -} - -impl std::cmp::PartialEq for Hash128 { - #[inline] - fn eq(&self, other: &Self) -> bool { - self.0 == other.0 - } -} - -impl nohash_hasher::IsEnabled for Hash128 {} - -impl std::fmt::Debug for Hash128 { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&format!("Hash128({:016X}{:016X})", self.0[0], self.0[1])) - } -} - -// ---------------------------------------------------------------------------- - pub const HASH_RANDOM_STATE: ahash::RandomState = ahash::RandomState::with_seeds(0, 1, 2, 3); -#[inline] -fn double_hash(value: impl std::hash::Hash + Copy) -> [u64; 2] { - [hash_with_seed(value, 123), hash_with_seed(value, 456)] -} - -/// Hash the given value. -#[inline] -fn hash_with_seed(value: impl std::hash::Hash, seed: u128) -> u64 { - use std::hash::Hash as _; - use std::hash::Hasher as _; - - // Don't use ahash::AHasher::default() since it uses a random number for seeding the hasher on every application start. - let mut hasher = HASH_RANDOM_STATE.build_hasher(); - seed.hash(&mut hasher); - value.hash(&mut hasher); - hasher.finish() -} - /// Hash the given value. #[inline] fn hash(value: impl std::hash::Hash) -> u64 {