aboutsummaryrefslogtreecommitdiff
path: root/incria/examples
diff options
context:
space:
mode:
Diffstat (limited to 'incria/examples')
-rw-r--r--incria/examples/spreadsheet.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/incria/examples/spreadsheet.rs b/incria/examples/spreadsheet.rs
index 40b1d5c..135ca80 100644
--- a/incria/examples/spreadsheet.rs
+++ b/incria/examples/spreadsheet.rs
@@ -1,6 +1,6 @@
use std::{future::Future, pin::Pin};
-use inc::{
+use incria::{
deps,
thunk::{Thunk, ThunkMapper},
Mapper,
@@ -11,41 +11,41 @@ type Key = (usize, usize);
type Value = usize;
#[derive(Debug, Default)]
-struct CellComputer;
+struct CellThunk;
-impl Thunk<Key, Value> for CellComputer {
+impl Thunk<Key, Value> for CellThunk {
fn compute(&self, key: Key) -> Pin<Box<dyn Future<Output = Value> + Send + '_>> {
Box::pin(async move {
if key.0 > 0 {
- let prev1 = *cell_store().get(&(key.0 - 1, key.1 - 1)).await;
- let prev2 = *cell_store().get(&(key.0 - 1, key.1)).await;
- let prev3 = *cell_store().get(&(key.0 - 1, key.1 + 1)).await;
+ let prev1 = *cell_mapping().get(&(key.0 - 1, key.1 - 1)).await;
+ let prev2 = *cell_mapping().get(&(key.0 - 1, key.1)).await;
+ let prev3 = *cell_mapping().get(&(key.0 - 1, key.1 + 1)).await;
prev1 + prev2 + prev3
} else {
- key.1
+ 1
}
})
}
}
-type CellStore = ThunkMapper<Key, Value, CellComputer>;
-static CELL_STORE: OnceCell<CellStore> = OnceCell::new();
-fn cell_store() -> &'static CellStore {
- CELL_STORE.get_or_init(CellStore::default)
+type CellMapping = ThunkMapper<Key, Value, CellThunk>;
+static CELL_MAPPING: OnceCell<CellMapping> = OnceCell::new();
+fn cell_mapping() -> &'static CellMapping {
+ CELL_MAPPING.get_or_init(CellMapping::default)
}
-const N: usize = 5;
+const N: usize = 20;
#[tokio::main]
async fn main() {
deps::with_node_id(deps::next_node_id(), async {
- let val = *dbg!(cell_store().get(&(N, N)).await);
+ let val = *dbg!(cell_mapping().get(&(N, N)).await);
// println!("{}", dep_graphviz());
deps::mark_dirty(21);
// println!("{}", dep_graphviz());
- assert_eq!(val, *cell_store().get(&(N, N)).await);
+ assert_eq!(val, *cell_mapping().get(&(N, N)).await);
println!("{}", deps::dep_graphviz());
})
.await;