Struct merkletree::merkle::MerkleTree

source ·
pub struct MerkleTree<E, A, S, BaseTreeArity = U2, SubTreeArity = U0, TopTreeArity = U0>
where E: Element, A: Algorithm<E>, S: Store<E>, BaseTreeArity: Unsigned, SubTreeArity: Unsigned, TopTreeArity: Unsigned,
{ /* private fields */ }

Implementations§

source§

impl<E: Element, A: Algorithm<E>, BaseTreeArity: Unsigned, SubTreeArity: Unsigned, TopTreeArity: Unsigned> MerkleTree<E, A, LevelCacheStore<E, File>, BaseTreeArity, SubTreeArity, TopTreeArity>

source

pub fn set_external_reader_path(&mut self, path: &Path) -> Result<()>

Given a pathbuf, instantiate an ExternalReader and set it for the LevelCacheStore.

source

pub fn from_store_configs_and_replica( leafs: usize, configs: &[StoreConfig], replica_config: &ReplicaConfig, ) -> Result<MerkleTree<E, A, LevelCacheStore<E, File>, BaseTreeArity, SubTreeArity, TopTreeArity>>

Given a set of StoreConfig’s (i.e on-disk references to levelcache stores) and replica config info, instantiate each tree and return a compound merkle tree with them. The ordering of the trees is significant, as trees are leaf indexed / addressable in the same sequence that they are provided here.

source

pub fn from_sub_tree_store_configs_and_replica( leafs: usize, configs: &[StoreConfig], replica_config: &ReplicaConfig, ) -> Result<MerkleTree<E, A, LevelCacheStore<E, File>, BaseTreeArity, SubTreeArity, TopTreeArity>>

Given a set of StoreConfig’s (i.e on-disk references to levelcache stores) and replica config info, instantiate each sub tree and return a compound merkle tree with them. The ordering of the trees is significant, as trees are leaf indexed / addressable in the same sequence that they are provided here.

source§

impl<E: Element, A: Algorithm<E>, S: Store<E>, BaseTreeArity: Unsigned, SubTreeArity: Unsigned, TopTreeArity: Unsigned> MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>

source

pub fn new<I: IntoIterator<Item = E>>( data: I, ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Creates new merkle from a sequence of hashes.

source

pub fn new_with_config<I: IntoIterator<Item = E>>( data: I, config: StoreConfig, ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Creates new merkle from a sequence of hashes.

source

pub fn from_data<O: Hashable<A>, I: IntoIterator<Item = O>>( data: I, ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Creates new merkle tree from a list of hashable objects.

source

pub fn from_data_with_config<O: Hashable<A>, I: IntoIterator<Item = O>>( data: I, config: StoreConfig, ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Creates new merkle tree from a list of hashable objects.

source

pub fn from_data_store( data: S, leafs: usize, ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Creates new merkle tree from an already allocated ‘Store’ (used with ‘Store::new_from_disk’). The specified ‘size’ is the number of base data leafs in the MT.

source

pub fn from_tree_slice( data: &[u8], leafs: usize, ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Represent a fully constructed merkle tree from a provided slice.

source

pub fn from_tree_slice_with_config( data: &[u8], leafs: usize, config: StoreConfig, ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Represent a fully constructed merkle tree from a provided slice.

source

pub fn from_trees( trees: Vec<MerkleTree<E, A, S, BaseTreeArity>>, ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Creates new compound merkle tree from a vector of merkle trees. The ordering of the trees is significant, as trees are leaf indexed / addressable in the same sequence that they are provided here.

source

pub fn from_sub_trees( trees: Vec<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity>>, ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Creates new top layer merkle tree from a vector of merkle trees with sub-trees. The ordering of the trees is significant, as trees are leaf indexed / addressable in the same sequence that they are provided here.

source

pub fn from_sub_trees_as_trees( trees: Vec<MerkleTree<E, A, S, BaseTreeArity>>, ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Creates new top layer merkle tree from a vector of merkle trees by first constructing the appropriate sub-trees. The ordering of the trees is significant, as trees are leaf indexed / addressable in the same sequence that they are provided here.

source

pub fn from_slices( tree_data: &[&[u8]], leafs: usize, ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity>>

Create a compound merkle tree given already constructed merkle trees contained as a slices. The ordering of the trees is significant, as trees are leaf indexed / addressable in the same sequence that they are provided here.

source

pub fn from_slices_with_configs( tree_data: &[&[u8]], leafs: usize, configs: &[StoreConfig], ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Create a compound merkle tree given already constructed merkle trees contained as a slices, along with configs for persistence. The ordering of the trees is significant, as trees are leaf indexed / addressable in the same sequence that they are provided here.

source

pub fn from_stores( leafs: usize, stores: Vec<S>, ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Given a set of Stores (i.e. backing to MTs), instantiate each tree and return a compound merkle tree with them. The ordering of the stores is significant, as trees are leaf indexed / addressable in the same sequence that they are provided here.

source

pub fn from_store_configs( leafs: usize, configs: &[StoreConfig], ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Given a set of StoreConfig’s (i.e on-disk references to disk stores), instantiate each tree and return a compound merkle tree with them. The ordering of the trees is significant, as trees are leaf indexed / addressable in the same sequence that they are provided here.

source

pub fn from_sub_tree_store_configs( leafs: usize, configs: &[StoreConfig], ) -> Result<MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>>

Given a set of StoreConfig’s (i.e on-disk references to dis stores), instantiate each sub tree and return a compound merkle tree with them. The ordering of the trees is significant, as trees are leaf indexed / addressable in the same sequence that they are provided here.

source

pub fn gen_proof(&self, i: usize) -> Result<Proof<E, BaseTreeArity>>

Generate merkle tree inclusion proof for leaf i

source

pub fn gen_cached_proof( &self, i: usize, rows_to_discard: Option<usize>, ) -> Result<Proof<E, BaseTreeArity>>

Generate merkle tree inclusion proof for leaf i by first building a partial tree (returned) along with the proof. ‘rows_to_discard’ is an option that will be used if set (even if it may cause an error), otherwise a reasonable default is chosen.

Return value is a Result tuple of the proof and the partial tree that was constructed.

source

pub fn root(&self) -> E

Returns merkle root

source

pub fn len(&self) -> usize

Returns number of elements in the tree.

source

pub fn compact( &mut self, config: StoreConfig, store_version: u32, ) -> Result<bool>

Truncates the data for later access via LevelCacheStore interface.

source

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

source

pub fn delete(&self, config: StoreConfig) -> Result<()>

Removes the backing store for this merkle tree.

source

pub fn is_empty(&self) -> bool

Returns true if the store contains no elements.

source

pub fn row_count(&self) -> usize

Returns row_count of the tree

source

pub fn leafs(&self) -> usize

Returns original number of elements the tree was built upon.

source

pub fn data(&self) -> Option<&S>

Returns data reference

source

pub fn read_at(&self, i: usize) -> Result<E>

Returns merkle leaf at index i

source

pub fn read_range(&self, start: usize, end: usize) -> Result<Vec<E>>

source

pub fn read_range_into( &self, start: usize, end: usize, buf: &mut [u8], ) -> Result<()>

source

pub fn read_into(&self, pos: usize, buf: &mut [u8]) -> Result<()>

Reads into a pre-allocated slice (for optimization purposes).

source

pub fn from_byte_slice_with_config( leafs: &[u8], config: StoreConfig, ) -> Result<Self>

Build the tree given a slice of all leafs, in bytes form.

source

pub fn from_byte_slice(leafs: &[u8]) -> Result<Self>

Build the tree given a slice of all leafs, in bytes form.

source§

impl<E: Element, A: Algorithm<E>, S: Store<E>, BaseTreeArity: Unsigned, SubTreeArity: Unsigned, TopTreeArity: Unsigned> MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>

source

pub fn try_from_iter<I: IntoIterator<Item = Result<E>>>(into: I) -> Result<Self>

Attempts to create a new merkle tree using hashable objects yielded by the provided iterator. This method returns the first error yielded by the iterator, if the iterator yielded an error.

source

pub fn try_from_iter_with_config<I: IntoIterator<Item = Result<E>>>( into: I, config: StoreConfig, ) -> Result<Self>

Attempts to create a new merkle tree using hashable objects yielded by the provided iterator and store config. This method returns the first error yielded by the iterator, if the iterator yielded an error.

Trait Implementations§

source§

impl<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity> Clone for MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>
where E: Element + Clone, A: Algorithm<E> + Clone, S: Store<E> + Clone, BaseTreeArity: Unsigned + Clone, SubTreeArity: Unsigned + Clone, TopTreeArity: Unsigned + Clone,

source§

fn clone( &self, ) -> MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>

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<E: Element, A: Algorithm<E>, S: Store<E>, BaseTreeArity: Unsigned, SubTreeArity: Unsigned, TopTreeArity: Unsigned> Debug for MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>

source§

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

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

impl<E: Element, A: Algorithm<E>, S: Store<E>, BaseTreeArity: Unsigned, SubTreeArity: Unsigned, TopTreeArity: Unsigned> FromIndexedParallelIterator<E, BaseTreeArity> for MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>

source§

fn from_par_iter<I>(into: I) -> Result<Self>

Creates new merkle tree from an iterator over hashable objects.

source§

fn from_par_iter_with_config<I>(into: I, config: StoreConfig) -> Result<Self>
where BaseTreeArity: Unsigned, I: IntoParallelIterator<Item = E>, I::Iter: IndexedParallelIterator,

Creates new merkle tree from an iterator over hashable objects.

source§

impl<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity> PartialEq for MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>
where E: Element + PartialEq, A: Algorithm<E> + PartialEq, S: Store<E> + PartialEq, BaseTreeArity: Unsigned + PartialEq, SubTreeArity: Unsigned + PartialEq, TopTreeArity: Unsigned + PartialEq,

source§

fn eq( &self, other: &MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>, ) -> 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<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity> Eq for MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>
where E: Element + Eq, A: Algorithm<E> + Eq, S: Store<E> + Eq, BaseTreeArity: Unsigned + Eq, SubTreeArity: Unsigned + Eq, TopTreeArity: Unsigned + Eq,

source§

impl<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity> StructuralPartialEq for MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>
where E: Element, A: Algorithm<E>, S: Store<E>, BaseTreeArity: Unsigned, SubTreeArity: Unsigned, TopTreeArity: Unsigned,

Auto Trait Implementations§

§

impl<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity> Freeze for MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>
where E: Freeze, S: Freeze,

§

impl<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity> RefUnwindSafe for MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>
where E: RefUnwindSafe, S: RefUnwindSafe, A: RefUnwindSafe, BaseTreeArity: RefUnwindSafe, SubTreeArity: RefUnwindSafe, TopTreeArity: RefUnwindSafe,

§

impl<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity> Send for MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>
where A: Send, BaseTreeArity: Send, SubTreeArity: Send, TopTreeArity: Send,

§

impl<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity> Sync for MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>
where A: Sync, BaseTreeArity: Sync, SubTreeArity: Sync, TopTreeArity: Sync,

§

impl<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity> Unpin for MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>
where E: Unpin, S: Unpin, A: Unpin, BaseTreeArity: Unpin, SubTreeArity: Unpin, TopTreeArity: Unpin,

§

impl<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity> UnwindSafe for MerkleTree<E, A, S, BaseTreeArity, SubTreeArity, TopTreeArity>
where E: UnwindSafe, S: UnwindSafe, A: UnwindSafe, BaseTreeArity: UnwindSafe, SubTreeArity: UnwindSafe, TopTreeArity: 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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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 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.