Enum grovedb_merk::tree::Link

source ·
pub enum Link {
    Reference {
        hash: CryptoHash,
        child_heights: (u8, u8),
        key: Vec<u8>,
        sum: Option<i64>,
    },
    Modified {
        pending_writes: usize,
        child_heights: (u8, u8),
        tree: TreeNode,
    },
    Uncommitted {
        hash: CryptoHash,
        child_heights: (u8, u8),
        tree: TreeNode,
        sum: Option<i64>,
    },
    Loaded {
        hash: CryptoHash,
        child_heights: (u8, u8),
        tree: TreeNode,
        sum: Option<i64>,
    },
}
Expand description

Represents a reference to a child tree node. Links may or may not contain the child’s Tree instance (storing its key if not).

Variants§

§

Reference

Represents a child tree node which has been pruned from memory, only retaining a reference to it (its key). The child node can always be fetched from the backing store by this key when necessary.

Fields

§hash: CryptoHash

Hash

§child_heights: (u8, u8)

Child heights

§key: Vec<u8>

Key

§sum: Option<i64>

Sum

§

Modified

Represents a tree node which has been modified since the Tree’s last hash computation. The child’s hash is not stored since it has not yet been recomputed. The child’s Tree instance is stored in the link.

Fields

§pending_writes: usize

Pending writes

§child_heights: (u8, u8)

Child heights

§tree: TreeNode

Tree

§

Uncommitted

Represents a tree node which has been modified since the Tree’s last commit, but which has an up-to-date hash. The child’s Tree instance is stored in the link.

Fields

§hash: CryptoHash

Hash

§child_heights: (u8, u8)

Child heights

§tree: TreeNode

Tree

§sum: Option<i64>

Sum

§

Loaded

Represents a tree node which has not been modified, has an up-to-date hash, and which is being retained in memory.

Fields

§hash: CryptoHash

Hash

§child_heights: (u8, u8)

Child heights

§tree: TreeNode

Tree

§sum: Option<i64>

Sum

Implementations§

source

pub const fn from_modified_tree(tree: TreeNode) -> Self

Creates a Link::Modified from the given Tree.

source

pub fn maybe_from_modified_tree(maybe_tree: Option<TreeNode>) -> Option<Self>

Creates a Link::Modified from the given tree, if any. If None, returns None.

source

pub const fn is_reference(&self) -> bool

Returns true if the link is of the Link::Reference variant.

source

pub const fn is_modified(&self) -> bool

Returns true if the link is of the Link::Modified variant.

source

pub const fn is_uncommitted(&self) -> bool

Returns true if the link is of the Link::Uncommitted variant.

source

pub const fn is_stored(&self) -> bool

Returns true if the link is of the Link::Loaded variant.

source

pub fn key(&self) -> &[u8]

Returns the key of the tree referenced by this link, as a slice.

source

pub const fn tree(&self) -> Option<&TreeNode>

Returns the Tree instance of the tree referenced by the link. If the link is of variant Link::Reference, the returned value will be None.

source

pub const fn hash(&self) -> &CryptoHash

Returns the hash of the tree referenced by the link. Panics if link is of variant Link::Modified since we have not yet recomputed the tree’s hash.

source

pub const fn sum(&self) -> Option<i64>

Returns the sum of the tree referenced by the link. Panics if link is of variant Link::Modified since we have not yet recomputed the tree’s hash.

source

pub const fn height(&self) -> u8

Returns the height of the children of the tree referenced by the link, if any (note: not the height of the referenced tree itself). Return value is (left_child_height, right_child_height).

source

pub const fn balance_factor(&self) -> i8

Returns the balance factor of the tree referenced by the link.

source

pub fn into_reference(self) -> Self

Consumes the link and converts to variant Link::Reference. Panics if the link is of variant Link::Modified or Link::Uncommitted.

Encoded link size

source

pub fn encoding_cost(&self) -> Result<usize>

The encoding cost is always 8 bytes for the sum instead of a varint

Trait Implementations§

source§

fn clone(&self) -> Link

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

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

Formats the value using the given formatter. Read more
source§

fn decode<R: Read>(input: R) -> Result<Self>

Reads bytes from the reader and returns the decoded value. Read more
source§

fn decode_into<R: Read>(&mut self, input: R) -> Result<()>

Reads bytes from the reader and mutates self to the decoded value. Read more
source§

fn encode_into<W: Write>(&self, out: &mut W) -> Result<()>

Writes the encoded representation of the value to the destination writer. Can error due to either a write error from dest, or an encoding error for types where invalid values are possible. Read more
source§

fn encoding_length(&self) -> Result<usize>

Calculates the length of the encoding for this value. Can error for types where invalid values are possible.
source§

fn encode(&self) -> Result<Vec<u8>, Error>

Returns the encoded representation of the value as a Vec<u8>. Read more
source§

fn eq(&self, other: &Link) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

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, dst: *mut T)

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

impl<T> CostsExt for T

source§

fn wrap_with_cost(self, cost: OperationCost) -> CostContext<Self>
where Self: Sized,

Wraps any value into a CostContext object with provided costs.
source§

fn wrap_fn_cost( self, f: impl FnOnce(&Self) -> OperationCost, ) -> CostContext<Self>
where Self: Sized,

Wraps any value into CostContext object with costs computed using the value getting wrapped.
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

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

§

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

§

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> TryFromVersioned<U> for T
where T: TryFrom<U>,

§

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

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

fn try_from_versioned( value: U, _grove_version: &GroveVersion, ) -> Result<T, <T as TryFromVersioned<U>>::Error>

Performs the conversion.
source§

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

§

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<T, U> TryIntoVersioned<U> for T
where U: TryFromVersioned<T>,

§

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

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

fn try_into_versioned( self, grove_version: &GroveVersion, ) -> Result<U, <U as TryFromVersioned<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V