pub struct SubTree<H: NodeHasher> {
pub root: SubTreeNode,
pub _marker: PhantomData<H>,
}Fields§
§root: SubTreeNode§_marker: PhantomData<H>Implementations§
Source§impl<H: NodeHasher> SubTree<H>
impl<H: NodeHasher> SubTree<H>
pub fn empty() -> Self
pub fn to_vec(&self) -> Result<Vec<u8>>
pub fn from_slice(buf: &[u8]) -> Result<Self>
pub fn compute_root(&self) -> Result<Hash>
pub fn hash(&self, value: &[u8]) -> Hash
pub fn is_empty(&self) -> bool
Sourcepub fn insert(&mut self, key: Hash, value_or_hash: ValueOrHash) -> Result<()>
pub fn insert(&mut self, key: Hash, value_or_hash: ValueOrHash) -> Result<()>
Inserts a key-value pair. Returns error if key already exists.
Sourcepub fn update(
&mut self,
key: Hash,
value_or_hash: ValueOrHash,
) -> Result<Option<ValueOrHash>>
pub fn update( &mut self, key: Hash, value_or_hash: ValueOrHash, ) -> Result<Option<ValueOrHash>>
Sets a key-value pair, replacing any existing value. Returns the previous value if the key existed.
pub fn contains(&self, key: &Hash) -> Result<bool>
pub fn delete(self, key: &Hash) -> Result<SubTree<H>>
pub fn iter(&self) -> SubtreeIter<'_> ⓘ
pub fn iter_mut(&mut self) -> SubtreeIterMut<'_> ⓘ
Source§impl<H: NodeHasher> SubTree<H>
impl<H: NodeHasher> SubTree<H>
Sourcepub fn prove(&self, keys: &[Hash], proof_type: ProofType) -> Result<SubTree<H>>
pub fn prove(&self, keys: &[Hash], proof_type: ProofType) -> Result<SubTree<H>>
Creates a new proof (SubTree) containing only the nodes necessary to prove the specified keys. This mirrors the prove() method on the main tree.
Sourcepub fn bucket_hashes(&self, bits: usize) -> Vec<Option<Hash>>
pub fn bucket_hashes(&self, bits: usize) -> Vec<Option<Hash>>
Returns hashes for 2^bits buckets based on key prefix.
Bucket i contains all keys where the first bits bits equal i.
Returns None for empty buckets or buckets that can’t be computed (hash nodes).
Sourcepub fn bucket_hashes_at_prefix(
&self,
prefix: &[bool],
bits: usize,
) -> Vec<Option<Hash>>
pub fn bucket_hashes_at_prefix( &self, prefix: &[bool], bits: usize, ) -> Vec<Option<Hash>>
Returns hashes for 2^bits buckets starting from a given prefix.
First navigates to the subtree at prefix, then returns bucket hashes
for bits additional levels.
Returns None for empty buckets or buckets that can’t be computed (hash nodes).
Sourcepub fn get_prefix(&self, prefix: &[bool]) -> Result<SubTree<H>>
pub fn get_prefix(&self, prefix: &[bool]) -> Result<SubTree<H>>
Get a subtree containing all keys that start with the given bit prefix. Returns a proper subtree with paths from the root - siblings not on the path are replaced with their hashes. The prefix is specified as a slice of bools (true = 1, false = 0).