Skip to content

Commit c0b4750

Browse files
committed
Expand documention on walk_subtree recursion
1 parent df8c826 commit c0b4750

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

crates/tlog_tiles/src/tlog.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -973,22 +973,32 @@ impl Subtree {
973973
// Recursive step: traverse the children.
974974
let (left, right) = self.children();
975975
if left.contains_subtree(m) {
976+
// `m` is fully included in the left child.
977+
//
976978
// Recurse on the left, fully include the right.
977979
let (mut recursive_proof, mut sibling) =
978980
(left.walk_subproof(m, known, f, strategy)?, f(&right));
979981
recursive_proof.append(&mut sibling);
980982
Ok(recursive_proof)
981983
} else {
982-
let (mut sibling, mut recursive_proof) = if right.contains_subtree(m) {
984+
let mut sibling = f(&left);
985+
let mut recursive_proof = if right.contains_subtree(m) {
986+
// `m` is fully included in the right child.
987+
//
983988
// Fully include the left, recurse on the right.
984-
(f(&left), right.walk_subproof(m, known, f, strategy)?)
989+
right.walk_subproof(m, known, f, strategy)?
985990
} else {
986-
// `m` is split across children. Fully include the left, recurse
987-
// on right child of `m` with `known` set to false as the right
988-
// child of `m` was not one of the inputs to the algorithm.
989-
assert!(m.lo == self.lo, "bad math in walk_subproof");
990-
let m_right = m.children().1;
991-
(f(&left), right.walk_subproof(&m_right, false, f, strategy)?)
991+
// `m` is fully included in `self`, but not fully included in
992+
// either the left or right child. This implies `m` has the left
993+
// child as a prefix and spills over into the right child
994+
// (otherwise, `m` would not be a valid subtree).
995+
//
996+
// Fully include the left, recurse on right child of `m` with
997+
// `known` set to false as the right child of `m` was not one of
998+
// the inputs to the algorithm.
999+
let (m_left, m_right) = m.children();
1000+
assert!(m_left == left, "expected left children to match");
1001+
right.walk_subproof(&m_right, false, f, strategy)?
9921002
};
9931003

9941004
match strategy {

0 commit comments

Comments
 (0)