pub trait CacheHashable {
// Required methods
fn invalidate_cache(&self);
fn invalidate_cache_recursive(&self);
fn get_cached_hash(&self) -> u64;
fn calculate_hash(&self) -> u64;
}Expand description
Types with an internally cached hash value.
Implementors store a precomputed hash (e.g. in metadata) to avoid rehashing entire subtrees on every cache lookup. The cached hash must be invalidated whenever the node’s content changes.
Use invalidate_cache for single-node
invalidation (e.g. when walking up ancestors after a replacement), and
invalidate_cache_recursive
for full-subtree invalidation (e.g. on rule replacement subtrees that may
contain cloned nodes with stale hashes from with_children reassembly).
Required Methods§
Sourcefn invalidate_cache(&self)
fn invalidate_cache(&self)
Invalidate the cached hash for this node only.
Used by mark_dirty_to_root when walking up ancestors after a child replacement.
Sourcefn invalidate_cache_recursive(&self)
fn invalidate_cache_recursive(&self)
Invalidate the cached hash for this node and all descendants. Used on replacement subtrees after rule application to clear stale hashes from cloned-and-reassembled nodes.
Sourcefn get_cached_hash(&self) -> u64
fn get_cached_hash(&self) -> u64
Return the cached hash, computing and storing it if not yet cached.
Sourcefn calculate_hash(&self) -> u64
fn calculate_hash(&self) -> u64
Compute the hash from scratch, store it, and return it.