Struct grin_store::prune_list::PruneList

source ·
pub struct PruneList { /* private fields */ }
Expand description

Maintains a list of previously pruned nodes in PMMR, compacting the list as parents get pruned and allowing checking whether a leaf is pruned. Given a node’s position, computes how much it should get shifted given the subtrees that have been pruned before.

The PruneList is useful when implementing compact backends for a PMMR (for example a single large byte array or a file). As nodes get pruned and removed from the backend to free space, the backend will get more compact but positions of a node within the PMMR will not match positions in the backend storage anymore. The PruneList accounts for that mismatch and does the position translation.

Implementations§

source§

impl PruneList

source

pub fn new(path: Option<PathBuf>, bitmap: Bitmap) -> PruneList

Instantiate a new prune list from the provided path and 1-based bitmap. Note: Does not flush the bitmap to disk. Caller is responsible for doing this.

source

pub fn empty() -> PruneList

Instatiate a new empty prune list.

source

pub fn open<P: AsRef<Path>>(path: P) -> Result<PruneList>

Open an existing prune_list or create a new one. Takes an optional bitmap of new pruned pos to be combined with existing pos.

source

pub fn init_caches(&mut self)

Init our internal shift caches.

source

pub fn flush(&mut self) -> Result<()>

Save the prune_list to disk.

source

pub fn get_total_shift(&self) -> u64

Return the total shift from all entries in the prune_list. This is the shift we need to account for when adding new entries to our PMMR.

source

pub fn get_total_leaf_shift(&self) -> u64

Return the total leaf_shift from all entries in the prune_list. This is the leaf_shift we need to account for when adding new entries to our PMMR.

source

pub fn get_shift(&self, pos0: u64) -> u64

Computes by how many positions a node at pos should be shifted given the number of nodes that have already been pruned before it. Note: the node at pos may be pruned and may be compacted away itself and the caller needs to be aware of this.

source

pub fn get_leaf_shift(&self, pos0: u64) -> u64

As above, but only returning the number of leaf nodes to skip for a given leaf. Helpful if, for instance, data for each leaf is being stored separately in a continuous flat-file.

source

pub fn append(&mut self, pos0: u64)

Push the node at the provided position in the prune list. Handles rollup of siblings and children as we go (relatively slow). Once we find a subtree root that can not be rolled up any further we cleanup everything beneath it and replace it with a single appended node.

source

pub fn len(&self) -> u64

Number of entries in the prune_list.

source

pub fn is_empty(&self) -> bool

Is the prune_list empty?

source

pub fn is_pruned(&self, pos0: u64) -> bool

A pos is pruned if it is a pruned root directly or if it is beneath the “next” pruned subtree. We only need to consider the “next” subtree due to the append-only MMR structure.

source

pub fn to_vec(&self) -> Vec<u64>

Convert the prune_list to a vec of pos.

source

pub fn shift_cache(&self) -> &[u64]

Internal shift cache as slice. only used in store/tests/prune_list.rs tests

source

pub fn leaf_shift_cache(&self) -> &[u64]

Internal leaf shift cache as slice. only used in store/tests/prune_list.rs tests

source

pub fn is_pruned_root(&self, pos0: u64) -> bool

Is the specified position a root of a pruned subtree?

source

pub fn iter(&self) -> impl Iterator<Item = u64> + '_

Iterator over the entries in the prune list (pruned roots).

source

pub fn pruned_bintree_range_iter(&self) -> impl Iterator<Item = Range<u64>> + '_

Iterator over the pruned “bintree range” for each pruned root.

source

pub fn unpruned_iter(&self, cutoff_pos: u64) -> impl Iterator<Item = u64> + '_

Iterator over all pos that are not pruned based on current prune_list.

source

pub fn unpruned_leaf_iter( &self, cutoff_pos: u64 ) -> impl Iterator<Item = u64> + '_

Iterator over all leaf pos that are not pruned based on current prune_list. Note this is not necessarily the same as the “leaf_set” as an output can be spent but not yet pruned.

source

pub fn bitmap(&self) -> Bitmap

Return a clone of our internal bitmap.

Trait Implementations§

source§

impl Debug for PruneList

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> SafeBorrow<T> for T
where T: ?Sized,

source§

fn borrow_replacement(ptr: &T) -> &T

Given ptr, which was obtained from a prior call to Self::borrow(), return a value with the same nominal lifetime which is guaranteed to survive mutations to Self. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DebugAny for T
where T: Any + Debug,

source§

impl<T> UnsafeAny for T
where T: Any,