Struct bridgetree::Checkpoint
source · pub struct Checkpoint { /* private fields */ }
Expand description
A data structure used to store the information necessary to “rewind” the state of a
BridgeTree
to a particular leaf position.
This is needed because the BridgeTree::marked_indices
map is a cache of information that
crosses MerkleBridge
boundaries, and so it is not sufficient to just truncate the list of
bridges; instead, we use Checkpoint
values to be able to rapidly restore the cache to its
previous state.
Implementations§
source§impl Checkpoint
impl Checkpoint
sourcepub fn from_parts(
bridges_len: usize,
is_marked: bool,
marked: BTreeSet<Position>,
forgotten: BTreeMap<Position, usize>
) -> Self
pub fn from_parts(
bridges_len: usize,
is_marked: bool,
marked: BTreeSet<Position>,
forgotten: BTreeMap<Position, usize>
) -> Self
Creates a new checkpoint from its constituent parts.
sourcepub fn at_length(bridges_len: usize, is_marked: bool) -> Self
pub fn at_length(bridges_len: usize, is_marked: bool) -> Self
Creates a new empty checkpoint for the specified BridgeTree
state.
Examples found in repository?
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
pub fn checkpoint(&mut self) {
match self.current_bridge.take() {
Some(cur_b) => {
let is_marked = self.get_marked_leaf(cur_b.position()).is_some();
// Do not create a duplicate bridge
if self
.prior_bridges
.last()
.map_or(false, |pb| pb.position() == cur_b.position())
{
self.current_bridge = Some(cur_b);
} else {
self.current_bridge = Some(cur_b.successor(false));
self.prior_bridges.push(cur_b);
}
self.checkpoints
.push(Checkpoint::at_length(self.prior_bridges.len(), is_marked));
}
None => {
self.checkpoints.push(Checkpoint::at_length(0, false));
}
}
if self.checkpoints.len() > self.max_checkpoints {
self.drop_oldest_checkpoint();
}
}
sourcepub fn bridges_len(&self) -> usize
pub fn bridges_len(&self) -> usize
Returns the length of the BridgeTree::prior_bridges
vector of the BridgeTree
to
which this checkpoint refers.
This is the number of bridges that will be retained in the event of a rewind to this checkpoint.
sourcepub fn is_marked(&self) -> bool
pub fn is_marked(&self) -> bool
Returns whether the current state of the tree had been marked at the point that this checkpoint was made.
In the event of a rewind, the rewind logic will ensure that mark information is properly reconstituted for the checkpointed tree state.
Trait Implementations§
source§impl Clone for Checkpoint
impl Clone for Checkpoint
source§fn clone(&self) -> Checkpoint
fn clone(&self) -> Checkpoint
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Checkpoint
impl Debug for Checkpoint
source§impl<'de> Deserialize<'de> for Checkpoint
impl<'de> Deserialize<'de> for Checkpoint
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl PartialEq<Checkpoint> for Checkpoint
impl PartialEq<Checkpoint> for Checkpoint
source§fn eq(&self, other: &Checkpoint) -> bool
fn eq(&self, other: &Checkpoint) -> bool
self
and other
values to be equal, and is used
by ==
.