shardtree: Make `BatchInsertionResult.max_insert_position` non-optional

This commit is contained in:
Jack Grigg 2024-11-23 04:03:50 +00:00
parent 166872e49b
commit c05f2fac00
3 changed files with 8 additions and 5 deletions

View File

@ -8,6 +8,9 @@ and this project adheres to Rust's notion of
## Unreleased ## Unreleased
### Changed ### Changed
- `shardtree::BatchInsertionResult.max_insert_position` now has type `Position`
instead of `Option<Position>` (all APIs return `Option<BatchInsertionResult>`
and use `None` at that level to represent "no leaves inserted").
- `shardtree::LocatedTree::from_parts` now returns `Option<Self>` (returning - `shardtree::LocatedTree::from_parts` now returns `Option<Self>` (returning
`None` if the provided `Address` and `Tree` are inconsistent). `None` if the provided `Address` and `Tree` are inconsistent).

View File

@ -71,8 +71,8 @@ impl<
values = res.remainder; values = res.remainder;
subtree_root_addr = subtree_root_addr.next_at_level(); subtree_root_addr = subtree_root_addr.next_at_level();
max_insert_position = res.max_insert_position; max_insert_position = Some(res.max_insert_position);
start = max_insert_position.unwrap() + 1; start = res.max_insert_position + 1;
all_incomplete.append(&mut res.incomplete); all_incomplete.append(&mut res.incomplete);
} else { } else {
break; break;
@ -102,7 +102,7 @@ pub struct BatchInsertionResult<H, C: Ord, I: Iterator<Item = (H, Retention<C>)>
/// [`Node::Nil`]: crate::tree::Node::Nil /// [`Node::Nil`]: crate::tree::Node::Nil
pub incomplete: Vec<IncompleteAt>, pub incomplete: Vec<IncompleteAt>,
/// The maximum position at which a leaf was inserted. /// The maximum position at which a leaf was inserted.
pub max_insert_position: Option<Position>, pub max_insert_position: Position,
/// The positions of all leaves with [`Retention::Checkpoint`] retention that were inserted. /// The positions of all leaves with [`Retention::Checkpoint`] retention that were inserted.
pub checkpoints: BTreeMap<C, Position>, pub checkpoints: BTreeMap<C, Position>,
/// The unconsumed remainder of the iterator from which leaves were inserted, if the tree /// The unconsumed remainder of the iterator from which leaves were inserted, if the tree
@ -243,7 +243,7 @@ impl<H: Hashable + Clone + PartialEq> LocatedPrunableTree<H> {
subtree: to_insert, subtree: to_insert,
contains_marked, contains_marked,
incomplete, incomplete,
max_insert_position: Some(last_position), max_insert_position: last_position,
checkpoints, checkpoints,
remainder: values, remainder: values,
}, },

View File

@ -787,7 +787,7 @@ impl<H: Hashable + Clone + PartialEq> LocatedPrunableTree<H> {
if r.remainder.next().is_some() { if r.remainder.next().is_some() {
Err(InsertionError::TreeFull) Err(InsertionError::TreeFull)
} else { } else {
Ok((r.subtree, r.max_insert_position.unwrap(), checkpoint_id)) Ok((r.subtree, r.max_insert_position, checkpoint_id))
} }
}) })
} }