Skip to main content

SubTree

Struct SubTree 

Source
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>

Source

pub fn empty() -> Self

Source

pub fn to_vec(&self) -> Result<Vec<u8>>

Source

pub fn from_slice(buf: &[u8]) -> Result<Self>

Source

pub fn compute_root(&self) -> Result<Hash>

Source

pub fn hash(&self, value: &[u8]) -> Hash

Source

pub fn is_empty(&self) -> bool

Source

pub fn insert(&mut self, key: Hash, value_or_hash: ValueOrHash) -> Result<()>

Inserts a key-value pair. Returns error if key already exists.

Source

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.

Source

pub fn contains(&self, key: &Hash) -> Result<bool>

Source

pub fn delete(self, key: &Hash) -> Result<SubTree<H>>

Source

pub fn iter(&self) -> SubtreeIter<'_>

Source

pub fn iter_mut(&mut self) -> SubtreeIterMut<'_>

Source§

impl<H: NodeHasher> SubTree<H>

Source

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.

Source

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).

Source

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).

Source

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).

Source

pub fn merge(self, other: SubTree<H>) -> Result<SubTree<H>>

Merges two subtrees into one. Both subtrees must have the same root hash. This is useful for combining proofs that cover different keys.

Source

pub fn entries_at_prefix(&self, prefix: &[bool]) -> Vec<(Hash, Hash)>

Returns all (key, value_hash) entries under the given prefix. This is bandwidth-efficient for sync - just the leaf data, no merkle paths.

Trait Implementations§

Source§

impl<H: NodeHasher> BorshDeserialize for SubTree<H>

Source§

fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl<H: NodeHasher> BorshSerialize for SubTree<H>

Source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

Source§

impl<H: Clone + NodeHasher> Clone for SubTree<H>

Source§

fn clone(&self) -> SubTree<H>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<H: Debug + NodeHasher> Debug for SubTree<H>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<H> Freeze for SubTree<H>

§

impl<H> RefUnwindSafe for SubTree<H>
where H: RefUnwindSafe,

§

impl<H> Send for SubTree<H>
where H: Send,

§

impl<H> Sync for SubTree<H>
where H: Sync,

§

impl<H> Unpin for SubTree<H>
where H: Unpin,

§

impl<H> UnsafeUnpin for SubTree<H>

§

impl<H> UnwindSafe for SubTree<H>
where H: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more