[][src]Struct red_memo::Memoizer

pub struct Memoizer<'a, K: 'a, V: 'a + Clone + Debug> { /* fields omitted */ }

Memoization cache for a recursive user function

Methods

impl<'a, K: 'a + Clone + Debug, V: 'a + Clone + Debug> Memoizer<'a, K, V>[src]

pub fn new_hash<F>(user: F) -> Self where
    K: Hash + Eq,
    F: 'a + Fn(&mut Memoizer<K, V>, &K) -> V, 
[src]

Creates a Memoizer based on HashMap.

pub fn new_ord<F>(user: F) -> Self where
    K: Ord,
    F: 'a + Fn(&mut Memoizer<K, V>, &K) -> V, 
[src]

Creates a Memoizer based on a BTreeMap.

pub fn lookup(&mut self, k: &K) -> V[src]

Looks up a key in the cache, calculating a value if necessary.

Panics

This method will panic if a circular dependency is detected.

Before the Memoizer starts calculating a value for a particular key, it places an "in-progress" marker in the cache for that key. After that key's value is caculated, the "in-progress" marker is replaced with the finished value. If an in-progress key is passed to lookup(), this indicates a circular dependency.

pub fn lookup_immut(&self, k: &K) -> Option<V>[src]

Look up a key in the cache, but do not calculate it if it is not present.

Trait Implementations

impl<'a, K: 'a + Clone + Debug, V: 'a + Clone + Debug> Debug for Memoizer<'a, K, V>[src]

Auto Trait Implementations

impl<'a, K, V> !Send for Memoizer<'a, K, V>

impl<'a, K, V> Unpin for Memoizer<'a, K, V>

impl<'a, K, V> !Sync for Memoizer<'a, K, V>

impl<'a, K, V> !UnwindSafe for Memoizer<'a, K, V>

impl<'a, K, V> !RefUnwindSafe for Memoizer<'a, K, V>

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]