Class InMemorySparseMerkleTree

    • Method Detail

      • init

        public static InMemorySparseMerkleTree init​(int height)
        Initialize an instance of InMemorySparseMerkleTree with specified height
        Parameters:
        height - the height of the tree
        Returns:
        an instance of InMemorySparseMerkleTree, allocated Rust side
      • isPositionEmpty

        public boolean isPositionEmpty​(long position)
                                throws Exception
        Check if specified position is empty
        Parameters:
        position - the index of the leaf to check
        Returns:
        True if no leaf is allocated at that position, False otherwise
        Throws:
        Exception - If position > 2^height - 1
      • addLeaves

        public void addLeaves​(Map<Long,​FieldElement> leaves)
                       throws Exception
        Add the specified leaves at the specified positions inside the tree. No internal updates in the tree will be triggered by this operation.
        Parameters:
        leaves - the leaves to be added to the tree and their corresponding index
        Throws:
        Exception - if one of the indices is > 2^height - 1
      • removeLeaves

        public void removeLeaves​(Set<Long> positions)
                          throws Exception
        Remove the specified leaves at the specified positions inside the tree. No internal updates in the tree will be triggered by this operation.
        Parameters:
        positions - a set of the indices of the leaves to be removed
        Throws:
        Exception - if one of the indices is > 2^height - 1 or if attempting to remove a non-existing leaf.
      • finalizeInPlace

        public void finalizeInPlace()
                             throws Exception
        Update the tree and the root with the leaves added/removed until this moment. The tree is modified in place and set to a "finalized" state. However, it is possibile to call this method as many times as possibile, with new leaves insertion/removal between each call, bringing again the tree to a "non-finalized" state.
        Throws:
        Exception - if it was not possible to update the tree correctly
      • root

        public FieldElement root()
                          throws Exception
        Return the root of the tree, only if the tree is in "finalized" state.
        Returns:
        The current root of the tree
        Throws:
        Exception - if the tree was not in "finalized" state
      • getMerklePath

        public MerklePath getMerklePath​(long leafPosition)
                                 throws Exception
        Return the MerklePath corresponding to the leaf at index leafPosition, only if the tree is in "finalized" state
        Parameters:
        leafPosition - the index of the leaf of which computing the Merkle Path
        Returns:
        the Merkle Path of the leaf at index leafPosition
        Throws:
        Exception - if the tree was not in "finalized" state
      • freeInMemorySparseMerkleTree

        public void freeInMemorySparseMerkleTree()
        Free memory Rust side