Struct zk_kit_pmt::tree::MerkleTree
source · pub struct MerkleTree<D, H>{
pub db: D,
/* private fields */
}
Expand description
The Merkle Tree structure
Fields§
§db: D
Implementations§
source§impl<D, H> MerkleTree<D, H>
impl<D, H> MerkleTree<D, H>
sourcepub fn default(depth: usize) -> PmtreeResult<Self>
pub fn default(depth: usize) -> PmtreeResult<Self>
Creates tree with specified depth and default “pmtree_db” dbpath.
sourcepub fn new(depth: usize, db_config: D::Config) -> PmtreeResult<Self>
pub fn new(depth: usize, db_config: D::Config) -> PmtreeResult<Self>
Creates new MerkleTree
and store it to the specified path/db
sourcepub fn load(db_config: D::Config) -> PmtreeResult<Self>
pub fn load(db_config: D::Config) -> PmtreeResult<Self>
Loads existing Merkle Tree from the specified path/db
sourcepub fn close(&mut self) -> PmtreeResult<()>
pub fn close(&mut self) -> PmtreeResult<()>
Closes the db connection
sourcepub fn set(&mut self, key: usize, leaf: H::Fr) -> PmtreeResult<()>
pub fn set(&mut self, key: usize, leaf: H::Fr) -> PmtreeResult<()>
Sets a leaf at the specified tree index
pub fn get_elem(&self, key: Key) -> PmtreeResult<H::Fr>
sourcepub fn delete(&mut self, key: usize) -> PmtreeResult<()>
pub fn delete(&mut self, key: usize) -> PmtreeResult<()>
Deletes a leaf at the key
by setting it to its default value
sourcepub fn update_next(&mut self, leaf: H::Fr) -> PmtreeResult<()>
pub fn update_next(&mut self, leaf: H::Fr) -> PmtreeResult<()>
Inserts a leaf to the next available index
sourcepub fn set_range<I: IntoIterator<Item = H::Fr>>(
&mut self,
start: usize,
leaves: I,
) -> PmtreeResult<()>
pub fn set_range<I: IntoIterator<Item = H::Fr>>( &mut self, start: usize, leaves: I, ) -> PmtreeResult<()>
Batch insertion from starting index
sourcepub fn batch_insert(
&mut self,
start: Option<usize>,
leaves: &[H::Fr],
) -> PmtreeResult<()>
pub fn batch_insert( &mut self, start: Option<usize>, leaves: &[H::Fr], ) -> PmtreeResult<()>
Batch insertion, updates the tree in parallel.
sourcepub fn proof(&self, index: usize) -> PmtreeResult<MerkleProof<H>>
pub fn proof(&self, index: usize) -> PmtreeResult<MerkleProof<H>>
Computes a Merkle proof for the leaf at the specified index
sourcepub fn verify(&self, leaf: &H::Fr, witness: &MerkleProof<H>) -> bool
pub fn verify(&self, leaf: &H::Fr, witness: &MerkleProof<H>) -> bool
Verifies a Merkle proof with respect to the input leaf and the tree root
sourcepub fn get(&self, key: usize) -> PmtreeResult<H::Fr>
pub fn get(&self, key: usize) -> PmtreeResult<H::Fr>
Returns the leaf by the key
sourcepub fn leaves_set(&self) -> usize
pub fn leaves_set(&self) -> usize
Returns the total number of leaves set
Auto Trait Implementations§
impl<D, H> Freeze for MerkleTree<D, H>
impl<D, H> RefUnwindSafe for MerkleTree<D, H>
impl<D, H> Send for MerkleTree<D, H>where
D: Send,
impl<D, H> Sync for MerkleTree<D, H>where
D: Sync,
impl<D, H> Unpin for MerkleTree<D, H>
impl<D, H> UnwindSafe for MerkleTree<D, H>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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