use crate::{Cell, Db, DbHandle};
mod hashmapped;
mod indexmapped;
mod macros;
mod singleton;
pub use hashmapped::HashMapStorage;
pub use indexmapped::TreeIndexStorage;
pub use singleton::SingletonStorage;
pub trait Storage: Sized {
fn output_is_unset(&self, cell: Cell, computation_id: u32) -> bool;
fn run_computation(db: &DbHandle<Self>, cell: Cell, computation_id: u32) -> bool;
fn gc(&mut self, used_cells: &std::collections::HashSet<Cell>);
fn input_debug_string(&self, db: &Db<Self>, cell: Cell) -> String;
fn clear_accumulated_for_cell(&self, cell: Cell);
}
pub trait StorageFor<C: Computation> {
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_input(&self, cell: Cell) -> C {
self.try_get_input(cell)
.expect("inc-complete internal error: get_input: expected input to be set")
}
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: &std::collections::HashSet<Cell>);
}
pub trait Computation {
type Output;
const IS_INPUT: bool;
const ASSUME_CHANGED: bool;
fn computation_id() -> u32;
}
pub trait Run<Storage>: Computation {
fn run(&self, db: &DbHandle<Storage>) -> Self::Output;
}