From f5adcd5a2ce06e93cffa1650fc3ea89b70183719 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Tue, 25 Jun 2024 15:04:12 -0600 Subject: [PATCH] shardtree: Fix pruning of annotated `Parent` nodes with `Nil` children. The current behavior of `unite` incorrectly discards annotation data. --- shardtree/CHANGELOG.md | 3 +++ shardtree/src/prunable.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/shardtree/CHANGELOG.md b/shardtree/CHANGELOG.md index 5175e78..d00ecde 100644 --- a/shardtree/CHANGELOG.md +++ b/shardtree/CHANGELOG.md @@ -24,6 +24,9 @@ and this project adheres to Rust's notion of - Fixes an error that could occur if an inserted `Frontier` node was interpreted as a node that had actually had its value observed as though it had been inserted using the ordinary tree insertion methods. +- Fixes an error in an internal method that could result in subtree root + annotation data being discarded when pruning a `Parent` node having + `Nil` nodes for both its left and right children. ## [0.3.1] - 2024-04-03 diff --git a/shardtree/src/prunable.rs b/shardtree/src/prunable.rs index d230093..1ec3052 100644 --- a/shardtree/src/prunable.rs +++ b/shardtree/src/prunable.rs @@ -312,7 +312,7 @@ impl PrunableTree { /// `level` must be the level of the two nodes that are being joined. pub(crate) fn unite(level: Level, ann: Option>, left: Self, right: Self) -> Self { match (left, right) { - (Tree(Node::Nil), Tree(Node::Nil)) => Tree::empty(), + (Tree(Node::Nil), Tree(Node::Nil)) if ann.is_none() => Tree::empty(), (Tree(Node::Leaf { value: lv }), Tree(Node::Leaf { value: rv })) // we can prune right-hand leaves that are not marked or reference leaves; if a // leaf is a checkpoint then that information will be propagated to the replacement