Struct zcash_history::Tree
source · [−]pub struct Tree<V: Version> { /* private fields */ }
Expand description
Represents partially loaded tree.
Some kind of “view” into the array representation of the MMR tree.
With only some of the leaves/nodes pre-loaded / pre-generated.
Exact amount of the loaded data can be calculated by the constructing party,
depending on the length of the tree and maximum amount of operations that are going
to happen after construction. Tree
should not be used as self-contained data structure,
since it’s internal state can grow indefinitely after serial operations.
Intended use of this Tree
is to instantiate it based on partially loaded data (see example
how to pick right nodes from the array representation of MMR Tree), perform several operations
(append-s/delete-s) and then drop it.
Implementations
sourceimpl<V: Version> Tree<V>
impl<V: Version> Tree<V>
sourcepub fn resolve_link(&self, link: EntryLink) -> Result<IndexedNode<'_, V>, Error>
pub fn resolve_link(&self, link: EntryLink) -> Result<IndexedNode<'_, V>, Error>
Resolve link originated from this tree
sourcepub fn new(
length: u32,
peaks: Vec<(u32, Entry<V>)>,
extra: Vec<(u32, Entry<V>)>
) -> Self
pub fn new(
length: u32,
peaks: Vec<(u32, Entry<V>)>,
extra: Vec<(u32, Entry<V>)>
) -> Self
New view into the the tree array representation
length
is total length of the array representation (is generally not a sum of
peaks.len + extra.len)
peaks
is peaks of the mmr tree
extra
is some extra nodes that calculated to be required during next one or more
operations on the tree.
Panics
Will panic if peaks
is empty.
sourcepub fn append_leaf(
&mut self,
new_leaf: V::NodeData
) -> Result<Vec<EntryLink>, Error>
pub fn append_leaf(
&mut self,
new_leaf: V::NodeData
) -> Result<Vec<EntryLink>, Error>
Append one leaf to the tree.
Returns links to actual nodes that has to be persisted as the result of the append.
If completed without error, at least one link to the appended
node (with metadata provided in new_leaf
) will be returned.
sourcepub fn truncate_leaf(&mut self) -> Result<u32, Error>
pub fn truncate_leaf(&mut self) -> Result<u32, Error>
Truncate one leaf from the end of the tree.
Returns actual number of nodes that should be removed by the caller from the end of the array representation.
Auto Trait Implementations
impl<V> RefUnwindSafe for Tree<V> where
<V as Version>::NodeData: RefUnwindSafe,
impl<V> Send for Tree<V> where
<V as Version>::NodeData: Send,
impl<V> Sync for Tree<V> where
<V as Version>::NodeData: Sync,
impl<V> Unpin for Tree<V> where
<V as Version>::NodeData: Unpin,
impl<V> UnwindSafe for Tree<V> where
<V as Version>::NodeData: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more