-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use hasher to compute resolution hash (#5495)
## Summary Addressing one TODO. This should be more efficient.
- Loading branch information
1 parent
e8d7c0c
commit 561625e
Showing
18 changed files
with
78 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
use std::hash::Hasher; | ||
|
||
use crate::cache_key::{CacheKey, CacheKeyHasher}; | ||
use seahash::SeaHasher; | ||
use std::hash::{Hash, Hasher}; | ||
|
||
/// Compute a hex string hash of a `CacheKey` object. | ||
/// | ||
/// The value returned by [`digest`] should be stable across releases and platforms. | ||
pub fn digest<H: CacheKey>(hashable: &H) -> String { | ||
/// The value returned by [`cache_digest`] should be stable across releases and platforms. | ||
pub fn cache_digest<H: CacheKey>(hashable: &H) -> String { | ||
/// Compute a u64 hash of a [`CacheKey`] object. | ||
fn cache_key_u64<H: CacheKey>(hashable: &H) -> u64 { | ||
let mut hasher = CacheKeyHasher::new(); | ||
hashable.cache_key(&mut hasher); | ||
hasher.finish() | ||
} | ||
|
||
to_hex(cache_key_u64(hashable)) | ||
} | ||
|
||
/// Compute a hex string hash of a hashable object. | ||
pub fn hash_digest<H: Hash>(hashable: &H) -> String { | ||
/// Compute a u64 hash of a hashable object. | ||
fn hash_u64<H: Hash>(hashable: &H) -> u64 { | ||
let mut hasher = SeaHasher::new(); | ||
hashable.hash(&mut hasher); | ||
hasher.finish() | ||
} | ||
|
||
to_hex(hash_u64(hashable)) | ||
} | ||
|
||
/// Convert a u64 to a hex string. | ||
fn to_hex(num: u64) -> String { | ||
hex::encode(num.to_le_bytes()) | ||
} | ||
|
||
/// Compute a u64 hash of a [`CacheKey`] object. | ||
fn cache_key_u64<H: CacheKey>(hashable: &H) -> u64 { | ||
let mut hasher = CacheKeyHasher::new(); | ||
hashable.cache_key(&mut hasher); | ||
hasher.finish() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,7 @@ impl CoreMetadata { | |
Clone, | ||
PartialEq, | ||
Eq, | ||
Hash, | ||
Serialize, | ||
Deserialize, | ||
rkyv::Archive, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.