Adds a `Retention` enum to the `incrementalmerkletree` crate.

This will be necessary in order to make the testing infrastructure
reusable for shardtree.
This commit is contained in:
Kris Nuttycombe 2022-12-15 12:19:59 -07:00
parent aa1d59f47a
commit 07a88c34ac
1 changed files with 22 additions and 0 deletions

View File

@ -10,6 +10,28 @@ use std::ops::{Add, AddAssign, Range, Sub};
#[cfg(feature = "test-dependencies")]
pub mod testing;
/// A type for metadata that is used to determine when and how a leaf can be pruned from a tree.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Retention<C> {
Ephemeral,
Checkpoint { id: C, is_marked: bool },
Marked,
}
impl<C> Retention<C> {
pub fn is_checkpoint(&self) -> bool {
matches!(self, Retention::Checkpoint { .. })
}
pub fn is_marked(&self) -> bool {
match self {
Retention::Ephemeral => false,
Retention::Checkpoint { is_marked, .. } => *is_marked,
Retention::Marked => true,
}
}
}
/// A type representing the position of a leaf in a Merkle tree.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[repr(transparent)]