Skip to main content

ContentMemo

Struct ContentMemo 

Source
pub struct ContentMemo<K, V>
where K: Eq + Hash,
{ /* private fields */ }
Expand description

A single-threaded content-keyed memo. K is the content address; the value Rc<V> is a pure function of K (see the module invariant). A hit is a cheap Rc::clone.

Implementations§

Source§

impl<K, V> ContentMemo<K, V>
where K: Eq + Hash + Clone,

Source

pub fn new() -> ContentMemo<K, V>

A fresh empty memo.

Source

pub fn get_or_compute(&self, key: K, compute: impl FnOnce() -> V) -> Rc<V>

Return the memoized value for key, computing + storing it via compute on a miss. A hit is a cheap Rc::clone and is byte-identical to a recompute by the module’s purity invariant (the caller’s responsibility — compute must be a pure function of key).

Source

pub fn clear(&self)

Drop all entries. Call at a natural boundary (e.g. per top-level eval) so stale keys from a prior computation cannot persist and collide.

Source

pub fn len(&self) -> usize

Number of memoized entries.

Source

pub fn is_empty(&self) -> bool

Whether the memo is empty.

Source§

impl<T, V> ContentMemo<ContentKey<T>, V>
where T: Hash,

Source

pub fn get_or_compute_keyed( &self, input: &T, compute: impl FnOnce(&T) -> V, ) -> Rc<V>

The keyed memo API — the M3 seal for the key↔content decoupling axis.

Derives the ContentKey from input internally (so the key is provably the content address of input, not some ambient value the caller passed alongside it) and hands the same &input to compute. A caller therefore cannot memoize under a key decoupled from the computed input — the decoupling has no constructor.

A hit is a cheap Rc::clone and is byte-identical to a recompute by the module’s purity invariantcompute must still be a pure function of its &T argument (the C1-ceiling purity axis this seal does NOT close; see ContentKey).

Trait Implementations§

Source§

impl<K, V> Debug for ContentMemo<K, V>
where K: Debug + Eq + Hash, V: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<K, V> Default for ContentMemo<K, V>
where K: Eq + Hash,

Source§

fn default() -> ContentMemo<K, V>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, V> !Freeze for ContentMemo<K, V>

§

impl<K, V> !RefUnwindSafe for ContentMemo<K, V>

§

impl<K, V> !Send for ContentMemo<K, V>

§

impl<K, V> !Sync for ContentMemo<K, V>

§

impl<K, V> Unpin for ContentMemo<K, V>
where K: Unpin,

§

impl<K, V> UnsafeUnpin for ContentMemo<K, V>

§

impl<K, V> UnwindSafe for ContentMemo<K, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.