From 9a15819c5b3c1e228571e01ba33483e467c2b2dd Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 28 Mar 2023 15:16:36 +0200 Subject: [PATCH 1/2] Change EntityPathHash to be 64 bit --- crates/re_log_types/src/hash.rs | 2 ++ crates/re_log_types/src/path/entity_path.rs | 18 +++++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/crates/re_log_types/src/hash.rs b/crates/re_log_types/src/hash.rs index 3ddcd13fbc4e..51f160b7cafb 100644 --- a/crates/re_log_types/src/hash.rs +++ b/crates/re_log_types/src/hash.rs @@ -12,6 +12,8 @@ use std::hash::BuildHasher; pub struct Hash64(u64); impl Hash64 { + pub const ZERO: Hash64 = Hash64(0); + pub fn hash(value: impl std::hash::Hash + Copy) -> Self { Self(hash(value)) } diff --git a/crates/re_log_types/src/path/entity_path.rs b/crates/re_log_types/src/path/entity_path.rs index 421d2c7c55db..c3f50a5a39bd 100644 --- a/crates/re_log_types/src/path/entity_path.rs +++ b/crates/re_log_types/src/path/entity_path.rs @@ -1,18 +1,18 @@ use std::sync::Arc; use crate::{ - hash::Hash128, parse_entity_path, path::entity_path_impl::EntityPathImpl, EntityPathPart, + hash::Hash64, parse_entity_path, path::entity_path_impl::EntityPathImpl, EntityPathPart, }; // ---------------------------------------------------------------------------- -/// A 128 bit hash of [`EntityPath`] with negligible risk of collision. +/// A 64 bit hash of [`EntityPath`] with very small risk of collision. #[derive(Copy, Clone, Eq)] -pub struct EntityPathHash(Hash128); +pub struct EntityPathHash(Hash64); impl EntityPathHash { /// Sometimes used as the hash of `None`. - pub const NONE: EntityPathHash = EntityPathHash(Hash128::ZERO); + pub const NONE: EntityPathHash = EntityPathHash(Hash64::ZERO); #[inline] pub fn hash64(&self) -> u64 { @@ -33,7 +33,7 @@ impl EntityPathHash { impl std::hash::Hash for EntityPathHash { #[inline] fn hash(&self, state: &mut H) { - state.write_u64(self.0.hash64()); + self.0.hash(state); } } @@ -48,11 +48,7 @@ impl nohash_hasher::IsEnabled for EntityPathHash {} impl std::fmt::Debug for EntityPathHash { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&format!( - "EntityPathHash({:016X}{:016X})", - self.0.first64(), - self.0.second64() - )) + f.write_str(&format!("EntityPathHash({:016X})", self.hash64())) } } @@ -154,7 +150,7 @@ impl From for EntityPath { #[inline] fn from(path: EntityPathImpl) -> Self { Self { - hash: EntityPathHash(Hash128::hash(&path)), + hash: EntityPathHash(Hash64::hash(&path)), path: Arc::new(path), } } From f4ce8761af30844226053bfe7265c3580686a1f6 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Tue, 28 Mar 2023 20:43:00 +0200 Subject: [PATCH 2/2] use write! macro instead of f.write_str Co-authored-by: Emil Ernerfeldt --- crates/re_log_types/src/path/entity_path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/re_log_types/src/path/entity_path.rs b/crates/re_log_types/src/path/entity_path.rs index c3f50a5a39bd..c956acd20293 100644 --- a/crates/re_log_types/src/path/entity_path.rs +++ b/crates/re_log_types/src/path/entity_path.rs @@ -48,7 +48,7 @@ impl nohash_hasher::IsEnabled for EntityPathHash {} impl std::fmt::Debug for EntityPathHash { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&format!("EntityPathHash({:016X})", self.hash64())) + write!(f, "EntityPathHash({:016X})", self.hash64()) } }