CompactableHeaplessTree

Struct CompactableHeaplessTree 

Source
pub struct CompactableHeaplessTree<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB = Proof<ARITY, HEIGHT, H, MAX_INPUT_LEN>>
where [(); { _ }]: Sized, Assert<{ _ }>: IsTrue, H: HashT, PB: ProofBuilder<ARITY, H>,
{ /* private fields */ }
Expand description

Tree that can be compacted after leaf removal and reduced to a smaller tree

Implementations§

Source§

impl<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB> CompactableHeaplessTree<ARITY, HEIGHT, H, MAX_INPUT_LEN, PB>
where [(); { _ }]: Sized, Assert<{ _ }>: IsTrue, H: HashT, PB: ProofBuilder<ARITY, H>,

Source

pub fn try_from<T: AsRef<[u8]> + Deref<Target = [u8]>>( input: &[T], ) -> Result<Self, Error>

creates a tree from an input if possible

Source

pub fn from<T: AsRef<[u8]> + Deref<Target = [u8]>>(input: &[T]) -> Self

creates a tree from an input if possible

Source

pub fn try_from_leaves(prefixed: &[Prefixed<ARITY, H>]) -> Result<Self, Error>

creates a tree from hashed leaves (of another tree)

Source

pub fn compact(&mut self)
where [(); { _ }]: Sized, H: HashT, PB: ProofBuilder<ARITY, H>,

move all existing leaves leftwards

Source

pub fn try_reduce( self, ) -> Result<CompactableHeaplessTree<ARITY, { _ }, H, MAX_INPUT_LEN, PB>, Self>
where [(); { _ }]: Sized, H: HashT, PB: ProofBuilder<ARITY, H>,

tries to compact this tree to a size of a tree with height-1 and create an instance of the new tree Note: takes ownership, but as it implements Copy trait may need explicit dropping to prevent being any longer available

Trait Implementations§

Source§

impl<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB> CanRemove for CompactableHeaplessTree<ARITY, HEIGHT, H, MAX_INPUT_LEN, PB>
where [(); { _ }]: Sized, Assert<{ _ }>: IsTrue, H: HashT, PB: ProofBuilder<ARITY, H>,

Source§

fn remove(&mut self, index: usize)

removes a leaf at index
Source§

fn num_of_leaves(&self) -> usize

number of leaves currently stored in the trsee
Source§

impl<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB> Clone for CompactableHeaplessTree<ARITY, HEIGHT, H, MAX_INPUT_LEN, PB>
where [(); { _ }]: Sized, Assert<{ _ }>: IsTrue, H: HashT, PB: ProofBuilder<ARITY, H>,

Source§

fn clone(&self) -> Self

Returns a duplicate 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<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB> Debug for CompactableHeaplessTree<ARITY, HEIGHT, H, MAX_INPUT_LEN, PB>
where [(); { _ }]: Sized, Assert<{ _ }>: IsTrue, H: HashT, PB: ProofBuilder<ARITY, H>,

Source§

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

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

impl<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB> Default for CompactableHeaplessTree<ARITY, HEIGHT, H, MAX_INPUT_LEN, PB>
where [(); { _ }]: Sized, Assert<{ _ }>: IsTrue, H: HashT, PB: ProofBuilder<ARITY, H>,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB> StaticTreeTrait<ARITY, H, PB> for CompactableHeaplessTree<ARITY, HEIGHT, H, MAX_INPUT_LEN, PB>
where [(); { _ }]: Sized, Assert<{ _ }>: IsTrue, H: HashT, PB: ProofBuilder<ARITY, H>,

Source§

fn generate_proof(&self, index: usize) -> PB

generate a proof for a leaf at index
Source§

fn replace(&mut self, index: usize, input: &[u8])

replace a leaf at index with a new value
Source§

fn replace_leaf(&mut self, index: usize, leaf: H::Output)

replace a hashed leaf at index with a new hashed value
Source§

fn root(&self) -> H::Output

return a root
Source§

fn leaves(&self) -> &[Prefixed<ARITY, H>]

return a slice of leaves
Source§

fn base_layer_size(&self) -> usize

a size (not necessarily a number of currently present leaves) of the leaf layer
Source§

fn arity(&self) -> usize

returns tree’s arity (determined at compile time)
Source§

fn height(&self) -> usize

returns tree’s height (determined at compile time)

Auto Trait Implementations§

§

impl<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB> Freeze for CompactableHeaplessTree<ARITY, HEIGHT, H, MAX_INPUT_LEN, PB>
where [(); { _ }]: Sized, <H as HashT>::Output: Freeze,

§

impl<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB> RefUnwindSafe for CompactableHeaplessTree<ARITY, HEIGHT, H, MAX_INPUT_LEN, PB>
where [(); { _ }]: Sized, <H as HashT>::Output: RefUnwindSafe,

§

impl<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB> Send for CompactableHeaplessTree<ARITY, HEIGHT, H, MAX_INPUT_LEN, PB>
where [(); { _ }]: Sized, <H as HashT>::Output: Send,

§

impl<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB> Sync for CompactableHeaplessTree<ARITY, HEIGHT, H, MAX_INPUT_LEN, PB>
where [(); { _ }]: Sized, <H as HashT>::Output: Sync,

§

impl<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB> Unpin for CompactableHeaplessTree<ARITY, HEIGHT, H, MAX_INPUT_LEN, PB>
where [(); { _ }]: Sized, <H as HashT>::Output: Unpin,

§

impl<const ARITY: usize, const HEIGHT: usize, H, const MAX_INPUT_LEN: usize, PB> UnwindSafe for CompactableHeaplessTree<ARITY, HEIGHT, H, MAX_INPUT_LEN, PB>
where [(); { _ }]: Sized, <H as HashT>::Output: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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