Skip to main content

StorageFor

Trait StorageFor 

Source
pub trait StorageFor<C: Computation> {
    // Required methods
    fn get_cell_for_computation(&self, key: &C) -> Option<Cell>;
    fn insert_new_cell(&self, cell: Cell, key: C);
    fn try_get_input(&self, cell: Cell) -> Option<C>;
    fn get_output(&self, cell: Cell) -> Option<C::Output>;
    fn update_output(&self, cell: Cell, new_value: C::Output) -> bool;
    fn gc(&mut self, used_cells: &HashSet<Cell>);

    // Provided method
    fn get_input(&self, cell: Cell) -> C { ... }
}
Expand description

This trait is implemented by a type storing a single computation type C. Examples include HashMapStorage<C>, SingletonStorage<C>, and BTreeMapStorage<C>.

To implement this efficiently, most types implementing this are two-way maps from C to Cell and from Cell to (C, Option<C::Output>).

Required Methods§

Source

fn get_cell_for_computation(&self, key: &C) -> Option<Cell>

Given a computation key, return the cell associated with it, if it exists.

Source

fn insert_new_cell(&self, cell: Cell, key: C)

Insert a new Cell with the given computation that has yet to be run

Source

fn try_get_input(&self, cell: Cell) -> Option<C>

Retrieve the input for this computation, returning None if not found.

Source

fn get_output(&self, cell: Cell) -> Option<C::Output>

Retrieve the output for the given cell, if it exists

Source

fn update_output(&self, cell: Cell, new_value: C::Output) -> bool

C has been re-run and has returned the output new_value, return true if new_value has changed from its previous value, and cache the new value if needed. If C::ASSUME_CHANGED is true, skip the comparison and assume the value changed.

Source

fn gc(&mut self, used_cells: &HashSet<Cell>)

Provided Methods§

Source

fn get_input(&self, cell: Cell) -> C

Retrieve the input for this computation. The input is expected to already be inserted into this storage.

Implementors§

Source§

impl<K> StorageFor<K> for SingletonStorage<K>
where K: Computation + Clone, K::Output: Eq + Clone,

Source§

impl<K> StorageFor<K> for TreeIndexStorage<K>
where K: Clone + Ord + Computation + 'static, K::Output: Clone + Eq,

Source§

impl<K, H> StorageFor<K> for HashMapStorage<K, H>
where K: Clone + Eq + Hash + Computation, K::Output: Eq + Clone, H: BuildHasher + Clone,