Struct dusk_merkle::Tree

source ·
pub struct Tree<T, const H: usize, const A: usize> { /* private fields */ }
Expand description

A sparse Merkle tree.

Implementations§

source§

impl<T, const H: usize, const A: usize> Tree<T, H, A>where T: Aggregate<A>,

source

pub const fn new() -> Self

Create a new merkle tree with the given initial root.

source

pub fn insert(&mut self, position: u64, item: impl Into<T>)

Insert an item at the given position in the tree.

Panics

If position >= capacity.

source

pub fn remove(&mut self, position: u64) -> Option<T>

Remove and return the item at the given position in the tree if it exists.

source

pub fn opening(&self, position: u64) -> Option<Opening<T, H, A>>where T: Clone,

Returns the Opening for the given position if it exists.

source

pub fn walk<W>(&self, walker: W) -> Walk<'_, T, W, H, A> where W: Fn(&T) -> bool,

Returns a Walk through the tree, proceeding according to the walker function.

A walk starts from the root of the tree, and “drills down” according to the output of the walker function. The function should return true or false, indicating whether the iterator should continue along the tree’s path.

source

pub fn root(&self) -> Ref<'_, T>

Get the root of the merkle tree.

source

pub fn smallest_subtree(&self) -> (Ref<'_, T>, usize)

Returns the root of the smallest sub-tree that holds all the leaves.

source

pub fn contains(&self, position: u64) -> bool

Returns true if the tree contains a leaf at the given position.

source

pub fn len(&self) -> u64

Returns the number of elements that have been inserted into the tree.

source

pub fn is_empty(&self) -> bool

Returns true if the tree is empty.

source

pub const fn capacity(&self) -> u64

The maximum number of leaves in the tree, i.e. its capacity.

Trait Implementations§

source§

impl<T: Clone, const H: usize, const A: usize> Clone for Tree<T, H, A>

source§

fn clone(&self) -> Tree<T, H, A>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug, const H: usize, const A: usize> Debug for Tree<T, H, A>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T: PartialEq, const H: usize, const A: usize> PartialEq for Tree<T, H, A>

source§

fn eq(&self, other: &Tree<T, H, A>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Eq, const H: usize, const A: usize> Eq for Tree<T, H, A>

source§

impl<T, const H: usize, const A: usize> StructuralEq for Tree<T, H, A>

source§

impl<T, const H: usize, const A: usize> StructuralPartialEq for Tree<T, H, A>

Auto Trait Implementations§

§

impl<T, const H: usize, const A: usize> !RefUnwindSafe for Tree<T, H, A>

§

impl<T, const H: usize, const A: usize> Send for Tree<T, H, A>where T: Send,

§

impl<T, const H: usize, const A: usize> !Sync for Tree<T, H, A>

§

impl<T, const H: usize, const A: usize> Unpin for Tree<T, H, A>where T: Unpin,

§

impl<T, const H: usize, const A: usize> UnwindSafe for Tree<T, H, A>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.