Struct light_indexed_merkle_tree::array::IndexedArray
source · pub struct IndexedArray<H, I, const ELEMENTS: usize>where
H: Hasher,
I: CheckedAdd + CheckedSub + Copy + Clone + PartialOrd + ToBytes + TryFrom<usize> + Unsigned,
usize: From<I>,{
pub elements: [IndexedElement<I>; ELEMENTS],
pub current_node_index: I,
pub highest_element_index: I,
/* private fields */
}Fields§
§elements: [IndexedElement<I>; ELEMENTS]§current_node_index: I§highest_element_index: IImplementations§
source§impl<H, I, const ELEMENTS: usize> IndexedArray<H, I, ELEMENTS>where
H: Hasher,
I: CheckedAdd + CheckedSub + Copy + Clone + PartialOrd + ToBytes + TryFrom<usize> + Unsigned,
usize: From<I>,
impl<H, I, const ELEMENTS: usize> IndexedArray<H, I, ELEMENTS>where
H: Hasher,
I: CheckedAdd + CheckedSub + Copy + Clone + PartialOrd + ToBytes + TryFrom<usize> + Unsigned,
usize: From<I>,
pub fn get(&self, index: usize) -> Option<&IndexedElement<I>>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn iter(&self) -> IndexingArrayIter<'_, H, I, ELEMENTS> ⓘ
pub fn find_element(&self, value: &BigUint) -> Option<&IndexedElement<I>>
pub fn init( &mut self, ) -> Result<IndexedElementBundle<I>, IndexedMerkleTreeError>
sourcepub fn find_low_element_index_for_nonexistent(
&self,
value: &BigUint,
) -> Result<I, IndexedMerkleTreeError>
pub fn find_low_element_index_for_nonexistent( &self, value: &BigUint, ) -> Result<I, IndexedMerkleTreeError>
Returns the index of the low element for the given value, which is
not yet the part of the array.
Low element is the greatest element which still has lower value than the provided one.
Low elements are used in non-membership proofs.
sourcepub fn find_low_element_for_nonexistent(
&self,
value: &BigUint,
) -> Result<(IndexedElement<I>, BigUint), IndexedMerkleTreeError>
pub fn find_low_element_for_nonexistent( &self, value: &BigUint, ) -> Result<(IndexedElement<I>, BigUint), IndexedMerkleTreeError>
Returns the:
- Low element for the given value.
- Next value for that low element.
For the given value, which is not yet the part of the array.
Low element is the greatest element which still has lower value than the provided one.
Low elements are used in non-membership proofs.
sourcepub fn find_low_element_index_for_existent(
&self,
value: &BigUint,
) -> Result<I, IndexedMerkleTreeError>
pub fn find_low_element_index_for_existent( &self, value: &BigUint, ) -> Result<I, IndexedMerkleTreeError>
Returns the index of the low element for the given value, which is
already the part of the array.
Low element is the greatest element which still has lower value than the provided one.
Low elements are used in non-membership proofs.
sourcepub fn find_low_element_for_existent(
&self,
value: &BigUint,
) -> Result<IndexedElement<I>, IndexedMerkleTreeError>
pub fn find_low_element_for_existent( &self, value: &BigUint, ) -> Result<IndexedElement<I>, IndexedMerkleTreeError>
Returns the low element for the given value, which is already the
part of the array.
Low element is the greatest element which still has lower value than the provided one.
Low elements are used in non-membership proofs.
sourcepub fn hash_element(&self, index: I) -> Result<[u8; 32], IndexedMerkleTreeError>
pub fn hash_element(&self, index: I) -> Result<[u8; 32], IndexedMerkleTreeError>
Returns the hash of the given element. That hash consists of:
- The value of the given element.
- The
next_indexof the given element. - The value of the element pointed by
next_index.
sourcepub fn new_element_with_low_element_index(
&self,
low_element_index: I,
value: &BigUint,
) -> Result<IndexedElementBundle<I>, IndexedMerkleTreeError>
pub fn new_element_with_low_element_index( &self, low_element_index: I, value: &BigUint, ) -> Result<IndexedElementBundle<I>, IndexedMerkleTreeError>
Returns an updated low element and a new element, created based on the
provided low_element_index and value.
pub fn new_element( &self, value: &BigUint, ) -> Result<IndexedElementBundle<I>, IndexedMerkleTreeError>
sourcepub fn append_with_low_element_index(
&mut self,
low_element_index: I,
value: &BigUint,
) -> Result<IndexedElementBundle<I>, IndexedMerkleTreeError>
pub fn append_with_low_element_index( &mut self, low_element_index: I, value: &BigUint, ) -> Result<IndexedElementBundle<I>, IndexedMerkleTreeError>
Appends the given value to the indexing array.
pub fn append( &mut self, value: &BigUint, ) -> Result<IndexedElementBundle<I>, IndexedMerkleTreeError>
pub fn lowest(&self) -> Option<IndexedElement<I>>
sourcepub fn dequeue_at_with_low_element_index(
&mut self,
low_element_index: I,
index: I,
) -> Result<Option<IndexedElement<I>>, IndexedMerkleTreeError>
pub fn dequeue_at_with_low_element_index( &mut self, low_element_index: I, index: I, ) -> Result<Option<IndexedElement<I>>, IndexedMerkleTreeError>
Returns and removes the element from the given index.
It also performs necessary updated of the remaning elements, to preserve the integrity of the array.
The low element under low_element_index is updated, to point to a new
next element instead of the one which is removed.
sourcepub fn dequeue_at(
&mut self,
index: I,
) -> Result<Option<IndexedElement<I>>, IndexedMerkleTreeError>
pub fn dequeue_at( &mut self, index: I, ) -> Result<Option<IndexedElement<I>>, IndexedMerkleTreeError>
Returns and removes the element from the given index.
It also performs necessary updates of the remaning elements, to preserve the integrity of the array. It searches for the low element and updates it, to point to a new next element instead of the one
Trait Implementations§
source§impl<H, I, const ELEMENTS: usize> Clone for IndexedArray<H, I, ELEMENTS>where
H: Hasher + Clone,
I: CheckedAdd + CheckedSub + Copy + Clone + PartialOrd + ToBytes + TryFrom<usize> + Unsigned + Clone,
usize: From<I>,
impl<H, I, const ELEMENTS: usize> Clone for IndexedArray<H, I, ELEMENTS>where
H: Hasher + Clone,
I: CheckedAdd + CheckedSub + Copy + Clone + PartialOrd + ToBytes + TryFrom<usize> + Unsigned + Clone,
usize: From<I>,
source§fn clone(&self) -> IndexedArray<H, I, ELEMENTS>
fn clone(&self) -> IndexedArray<H, I, ELEMENTS>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<H, I, const ELEMENTS: usize> Debug for IndexedArray<H, I, ELEMENTS>where
H: Hasher + Debug,
I: CheckedAdd + CheckedSub + Copy + Clone + PartialOrd + ToBytes + TryFrom<usize> + Unsigned + Debug,
usize: From<I>,
impl<H, I, const ELEMENTS: usize> Debug for IndexedArray<H, I, ELEMENTS>where
H: Hasher + Debug,
I: CheckedAdd + CheckedSub + Copy + Clone + PartialOrd + ToBytes + TryFrom<usize> + Unsigned + Debug,
usize: From<I>,
Auto Trait Implementations§
impl<H, I, const ELEMENTS: usize> Freeze for IndexedArray<H, I, ELEMENTS>
impl<H, I, const ELEMENTS: usize> RefUnwindSafe for IndexedArray<H, I, ELEMENTS>
impl<H, I, const ELEMENTS: usize> Send for IndexedArray<H, I, ELEMENTS>
impl<H, I, const ELEMENTS: usize> Sync for IndexedArray<H, I, ELEMENTS>
impl<H, I, const ELEMENTS: usize> Unpin for IndexedArray<H, I, ELEMENTS>
impl<H, I, const ELEMENTS: usize> UnwindSafe for IndexedArray<H, I, ELEMENTS>
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
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>
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>
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