shardtree: `Nil` nodes cannot replace any other sort of node in the tree.

This commit is contained in:
Kris Nuttycombe 2024-05-15 14:36:27 -06:00
parent 811d384bd4
commit 57b6e8999f
1 changed files with 100 additions and 95 deletions

View File

@ -547,6 +547,16 @@ impl<H: Hashable + Clone + PartialEq> LocatedPrunableTree<H> {
is_complete: bool,
contains_marked: bool,
) -> Result<(PrunableTree<H>, Vec<IncompleteAt>), InsertionError> {
trace!(
root_addr = ?root_addr,
max_position = ?LocatedTree::max_position_internal(root_addr, into),
to_insert = ?subtree.root_addr(),
"Subtree insert"
);
// An empty tree cannot replace any other type of tree.
if subtree.root().is_nil() {
Ok((into.clone(), vec![]))
} else {
// In the case that we are replacing a node entirely, we need to extend the
// subtree up to the level of the node being replaced, adding Nil siblings
// and recording the presence of those incomplete nodes when necessary
@ -578,12 +588,6 @@ impl<H: Hashable + Clone + PartialEq> LocatedPrunableTree<H> {
(node.root.reannotate_root(ann), incomplete)
};
trace!(
root_addr = ?root_addr,
max_position = ?LocatedTree::max_position_internal(root_addr, into),
to_insert = ?subtree.root_addr(),
"Subtree insert"
);
match into {
Tree(Node::Nil) => Ok(replacement(None, subtree)),
Tree(Node::Leaf { value: (value, _) }) => {
@ -599,7 +603,7 @@ impl<H: Hashable + Clone + PartialEq> LocatedPrunableTree<H> {
vec![],
))
} else {
trace!(
warn!(
cur_root = ?value,
new_root = ?subtree.root.node_value(),
"Insertion conflict",
@ -656,6 +660,7 @@ impl<H: Hashable + Clone + PartialEq> LocatedPrunableTree<H> {
}
}
}
}
let max_position = self.max_position();
trace!(