FlatTree

Struct FlatTree 

Source
pub struct FlatTree<'a, T> { /* private fields */ }
Expand description

Representation of a flat tree of element type T where the 'a is the life-time parameter of the underlying FlatStore.

At the moment the tree is append only, i.e. it can add new leave elements but not update or deletion.

Implementations§

Source§

impl<'a, T: Merkleable> FlatTree<'a, T>

Source

pub fn new(store: &'a dyn FlatStore<T>, size: u64) -> Self

Return a FlatTree object of given size with the underlying FlatStore as storage. If a non-zero size is given, it assumes a valid tree has been previously created on the same store.

Source

pub fn depth(&self) -> usize

Depth of a full tree.

Source

pub fn width(&self) -> u64

Width of the tree (number of leave nodes).

Source

pub fn is_empty(&self) -> bool

Return true if tree is empty.

Source

pub fn len(&self) -> u64

Number of leaves in the tree (same as width).

Source

pub fn push(&mut self, value: T)

Append a leaf value to the tree.

Source

pub fn append(&mut self, value: Vec<T>)

Append a number of leaf values to the tree.

Source

pub fn get(&self, leaf_index: u64) -> Option<T>

Return the value at a given leaf index if it exists.

Source

pub fn iter(&self) -> Box<dyn Iterator<Item = T> + '_>

Iterate over all leaf values.

Source

pub fn root(&self) -> T

Return the top root of the full tree.

Source

pub fn local_path(&self, i: u64) -> LocalPathIterator<'_, T>

Return the merkle path iterating from the leaf at the given index to one of the local roots.

Source

pub fn full_path(&self, i: u64) -> FullPathIterator<'_, T>

Return the merkle path iterating from the leaf at the given index to top root.

Source

pub fn full_path_from_node_index(&self, i: u64) -> FullPathIterator<'_, T>
where T: Clone,

Return the full path iterating from the given node index (either leaf or branch node) to top root. Note that for leaf nodes, node_index = leaf_index * 2.

Auto Trait Implementations§

§

impl<'a, T> Freeze for FlatTree<'a, T>

§

impl<'a, T> !RefUnwindSafe for FlatTree<'a, T>

§

impl<'a, T> !Send for FlatTree<'a, T>

§

impl<'a, T> !Sync for FlatTree<'a, T>

§

impl<'a, T> Unpin for FlatTree<'a, T>

§

impl<'a, T> !UnwindSafe for FlatTree<'a, T>

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.