Skip to content

Commit 65e2251

Browse files
committed
refactor: more ergonomic WorkplanItem
1 parent 4d0e96f commit 65e2251

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

mp2-v1/tests/common/cases/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ where
565565
// closure performing all the operations necessary beofre jumping to the next iteration
566566
let mut end_iteration = |proven_nodes: &mut HashSet<K>| -> Result<()> {
567567
proven_nodes.insert(k.clone());
568-
workplan.done(&wk)?;
568+
workplan.done(wk.k())?;
569569
Ok(())
570570
};
571571
// since epoch starts at genesis now, we can directly give the value of the block

mp2-v1/tests/common/celltree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl TestContext {
178178
.unwrap()
179179
)
180180
);
181-
workplan.done(&wk).unwrap();
181+
workplan.done(wk.k()).unwrap();
182182
}
183183
let root = tree.root().await.unwrap();
184184
let root_data = tree.root_data().await.unwrap();

mp2-v1/tests/common/index_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl TestContext {
200200
.store_proof(ProofKey::Index(proof_key), proof)
201201
.expect("unable to store index tree proof");
202202

203-
workplan.done(&wk).unwrap();
203+
workplan.done(wk.k()).unwrap();
204204
}
205205
let root = t.root().await.unwrap();
206206
let root_proof_key = IndexProofIdentifier {

mp2-v1/tests/common/rowtree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl TestContext {
238238
new_proof_key,
239239
hex::encode(extract_hash_from_proof(&proof).unwrap().to_bytes())
240240
);
241-
workplan.done(&wk).unwrap();
241+
workplan.done(wk.k()).unwrap();
242242
}
243243
let root = t.root().await.unwrap();
244244
let row = table.row.fetch(&root).await;

ryhope/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ where
166166

167167
let mut payload = self.storage.data().fetch(item.k()).await;
168168
payload.aggregate(child_data.into_iter());
169-
plan.done(&item)?;
169+
plan.done(&item.k())?;
170170
self.storage
171171
.data_mut()
172172
.store(item.k().to_owned(), payload)

ryhope/src/storage/updatetree.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,22 @@ impl<K: Clone + Hash + Eq + Debug> WorkplanItem<K> {
383383
WorkplanItem::Subtree { k, .. } | WorkplanItem::Node { k, .. } => k,
384384
}
385385
}
386+
387+
pub fn as_subtree(&self) -> &UpdateTree<K> {
388+
if let WorkplanItem::Subtree { subtree, .. } = self {
389+
subtree
390+
} else {
391+
unreachable!()
392+
}
393+
}
394+
395+
pub fn as_node(&self) -> bool {
396+
if let WorkplanItem::Node { is_path_end, .. } = self {
397+
*is_path_end
398+
} else {
399+
unreachable!()
400+
}
401+
}
386402
}
387403

388404
/// An update plan to recompute all the hashes of the touched nodes stored in a
@@ -419,15 +435,11 @@ impl<T: Debug + Clone + Hash + Eq> UpdatePlan<T> {
419435

420436
/// Mark the given item as having been completed. Its dependent will not be
421437
/// generated by the iterator until the item has been marked as completed.
422-
pub fn done(&mut self, item: &WorkplanItem<T>) -> Result<()> {
423-
let i = *self
424-
.t
425-
.idx
426-
.get(&item.k())
427-
.ok_or_else(|| anyhow!("unknwown key"))?;
438+
pub fn done(&mut self, k: &T) -> Result<()> {
439+
let i = *self.t.idx.get(k).ok_or_else(|| anyhow!("unknwown key"))?;
428440

429441
// May happen when restarting a plan
430-
self.anchors.retain(|k| k != item.k());
442+
self.anchors.retain(|_k| _k != k);
431443

432444
// Root node is hardcoded to 0
433445
if i == 0 {
@@ -541,14 +553,14 @@ mod tests {
541553

542554
loop {
543555
let mut done = vec![];
544-
while let Some(Next::Ready(k)) = workplan.next() {
545-
println!("Doing {}", k.k());
546-
done.push(k);
556+
while let Some(Next::Ready(item)) = workplan.next() {
557+
println!("Doing {}", item.k());
558+
done.push(item);
547559
workplan.t.print();
548560
}
549561

550562
for d in done.iter() {
551-
workplan.done(d).unwrap();
563+
workplan.done(d.k()).unwrap();
552564
}
553565
if done.is_empty() {
554566
break;
@@ -599,7 +611,7 @@ mod tests {
599611
count_done += 1;
600612
}
601613
}
602-
workplan.done(&item).unwrap();
614+
workplan.done(item.k()).unwrap();
603615
}
604616

605617
assert_eq!(count_done, mt.nodes.len());

0 commit comments

Comments
 (0)