Skip to main content

CacheHashable

Trait CacheHashable 

Source
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§

Source

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.

Source

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.

Source

fn get_cached_hash(&self) -> u64

Return the cached hash, computing and storing it if not yet cached.

Source

fn calculate_hash(&self) -> u64

Compute the hash from scratch, store it, and return it.

Implementors§