Drop MemoHash's std Hash impl and route cache-identity hashing through CacheHash (#4209)

This commit is contained in:
Dennis Kobert
2026-06-07 19:49:56 +02:00
committed by GitHub
parent 2c29d2c406
commit d5c67eeb55
4 changed files with 32 additions and 16 deletions

View File

@@ -11,12 +11,34 @@ pub struct IORecord<I, O> {
pub output: O,
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
#[derive(Clone, Debug)]
pub struct MemoHash<T: CacheHash> {
hash: u64,
value: Arc<T>,
}
// Compare the value, not the cache `hash`: `CacheHash` is not guaranteed to be an equivalence relation,
// so it can't back `eq`/`cmp`. Cache-identity hashing goes through `CacheHash`.
impl<T: CacheHash + PartialEq> PartialEq for MemoHash<T> {
fn eq(&self, other: &Self) -> bool {
self.value == other.value
}
}
impl<T: CacheHash + Eq> Eq for MemoHash<T> {}
impl<T: CacheHash + PartialOrd> PartialOrd for MemoHash<T> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
self.value.partial_cmp(&other.value)
}
}
impl<T: CacheHash + Ord> Ord for MemoHash<T> {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.value.cmp(&other.value)
}
}
impl<'de, T: serde::Deserialize<'de> + CacheHash> serde::Deserialize<'de> for MemoHash<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -67,12 +89,6 @@ impl<T: CacheHash> From<T> for MemoHash<T> {
}
}
impl<T: CacheHash> Hash for MemoHash<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.hash.hash(state)
}
}
impl<T: CacheHash> CacheHash for MemoHash<T> {
fn cache_hash<H: Hasher>(&self, state: &mut H) {
self.hash.hash(state);

View File

@@ -31,7 +31,7 @@ pub trait Transform {
/// - `skew`: the horizontal shear coefficient (the raw matrix value, not an angle)
///
/// The original transform can be reconstructed as:
/// ```
/// ```ignore
/// DAffine2::from_scale_angle_translation(scale, rotation, translation) * DAffine2::from_cols_array(&[1., 0., skew, 1., 0., 0.])
/// ```
#[inline(always)]