Struct diem_types::proof::accumulator::InMemoryAccumulator
source · pub struct InMemoryAccumulator<H> { /* private fields */ }
Expand description
The Accumulator implementation.
Implementations§
source§impl<H> InMemoryAccumulator<H>where
H: CryptoHasher,
impl<H> InMemoryAccumulator<H>where H: CryptoHasher,
sourcepub fn new(
frozen_subtree_roots: Vec<HashValue>,
num_leaves: LeafCount
) -> Result<Self>
pub fn new( frozen_subtree_roots: Vec<HashValue>, num_leaves: LeafCount ) -> Result<Self>
Constructs a new accumulator with roots of existing frozen subtrees. Returns error if the number of frozen subtree roots does not match the number of leaves.
sourcepub fn from_leaves(leaves: &[HashValue]) -> Self
pub fn from_leaves(leaves: &[HashValue]) -> Self
Constructs a new accumulator with given leaves.
sourcepub fn append(&self, leaves: &[HashValue]) -> Self
pub fn append(&self, leaves: &[HashValue]) -> Self
Appends a list of new leaves to an existing accumulator. Since the accumulator is immutable, the existing one remains unchanged and a new one representing the result is returned.
sourcepub fn append_subtrees(
&self,
subtrees: &[HashValue],
num_new_leaves: LeafCount
) -> Result<Self>
pub fn append_subtrees( &self, subtrees: &[HashValue], num_new_leaves: LeafCount ) -> Result<Self>
Appends a list of new subtrees to the existing accumulator. This is similar to
append
except that the new leaves themselves are not known and
they are represented by subtrees
. As an example, given the following accumulator that
currently has 10 leaves, the frozen subtree roots and the new subtrees are annotated below.
Note that in this case subtrees[0]
represents two new leaves A
and B
, subtrees[1]
represents four new leaves C
, D
, E
and F
, subtrees[2]
represents four new leaves
G
, H
, I
and J
, and the last subtrees[3]
represents one new leaf K
.
new_root
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
old_root o
/ \ / \
/ \ / placeholder
/ \ /
/ \ /
/ \ /
/ \ o
/ \ / \
/ \ / \
/ o / \
frozen_subtree_roots[0] / \ / \
/ \ / \ / \
/ \ / \ / \
o o o subtrees[1] subtrees[2] o
/ \ / \ / \ / \ / \ / \
o o o o frozen_subtree_roots[1] subtrees[0] o o o o o placeholder
/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
o o o o o o o o o o A B C D E F G H I J K (subtrees[3]) placeholder
pub fn version(&self) -> u64
sourcepub fn frozen_subtree_roots(&self) -> &Vec<HashValue> ⓘ
pub fn frozen_subtree_roots(&self) -> &Vec<HashValue> ⓘ
Returns the set of frozen subtree roots in this accumulator
sourcepub fn num_leaves(&self) -> LeafCount
pub fn num_leaves(&self) -> LeafCount
Returns the total number of leaves in this accumulator.
Trait Implementations§
source§impl<H: Clone> Clone for InMemoryAccumulator<H>
impl<H: Clone> Clone for InMemoryAccumulator<H>
source§fn clone(&self) -> InMemoryAccumulator<H>
fn clone(&self) -> InMemoryAccumulator<H>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<H: Debug> Debug for InMemoryAccumulator<H>
impl<H: Debug> Debug for InMemoryAccumulator<H>
source§impl<H> Default for InMemoryAccumulator<H>where
H: CryptoHasher,
impl<H> Default for InMemoryAccumulator<H>where H: CryptoHasher,
source§impl<'de, H> Deserialize<'de> for InMemoryAccumulator<H>
impl<'de, H> Deserialize<'de> for InMemoryAccumulator<H>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<H> PartialEq<InMemoryAccumulator<H>> for InMemoryAccumulator<H>
impl<H> PartialEq<InMemoryAccumulator<H>> for InMemoryAccumulator<H>
source§impl<H> Serialize for InMemoryAccumulator<H>
impl<H> Serialize for InMemoryAccumulator<H>
impl<H> Eq for InMemoryAccumulator<H>
Auto Trait Implementations§
impl<H> RefUnwindSafe for InMemoryAccumulator<H>where H: RefUnwindSafe,
impl<H> Send for InMemoryAccumulator<H>where H: Send,
impl<H> Sync for InMemoryAccumulator<H>where H: Sync,
impl<H> Unpin for InMemoryAccumulator<H>where H: Unpin,
impl<H> UnwindSafe for InMemoryAccumulator<H>where H: UnwindSafe,
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.