Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change EntityPathHash to be 64 bit #1723

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/re_log_types/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
18 changes: 7 additions & 11 deletions crates/re_log_types/src/path/entity_path.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -33,7 +33,7 @@ impl EntityPathHash {
impl std::hash::Hash for EntityPathHash {
#[inline]
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
state.write_u64(self.0.hash64());
self.0.hash(state);
}
}

Expand All @@ -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()
))
write!(f, "EntityPathHash({:016X})", self.hash64())
}
}

Expand Down Expand Up @@ -154,7 +150,7 @@ impl From<EntityPathImpl> for EntityPath {
#[inline]
fn from(path: EntityPathImpl) -> Self {
Self {
hash: EntityPathHash(Hash128::hash(&path)),
hash: EntityPathHash(Hash64::hash(&path)),
path: Arc::new(path),
}
}
Expand Down