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: CryptoHashHash
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
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: CryptoHashHash
Loaded
Represents a tree node which has not been modified, has an up-to-date hash, and which is being retained in memory.
Implementations§
source§impl Link
impl Link
sourcepub const fn from_modified_tree(tree: TreeNode) -> Self
pub const fn from_modified_tree(tree: TreeNode) -> Self
Creates a Link::Modified from the given Tree.
sourcepub fn maybe_from_modified_tree(maybe_tree: Option<TreeNode>) -> Option<Self>
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.
sourcepub const fn is_reference(&self) -> bool
pub const fn is_reference(&self) -> bool
Returns true if the link is of the Link::Reference variant.
sourcepub const fn is_modified(&self) -> bool
pub const fn is_modified(&self) -> bool
Returns true if the link is of the Link::Modified variant.
sourcepub const fn is_uncommitted(&self) -> bool
pub const fn is_uncommitted(&self) -> bool
Returns true if the link is of the Link::Uncommitted variant.
sourcepub const fn tree(&self) -> Option<&TreeNode>
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.
sourcepub const fn hash(&self) -> &CryptoHash
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.
sourcepub const fn sum(&self) -> Option<i64>
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.
sourcepub const fn height(&self) -> u8
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).
sourcepub const fn balance_factor(&self) -> i8
pub const fn balance_factor(&self) -> i8
Returns the balance factor of the tree referenced by the link.
sourcepub fn into_reference(self) -> Self
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.
sourcepub const fn encoded_link_size(
not_prefixed_key_len: u32,
is_sum_tree: bool,
) -> u32
pub const fn encoded_link_size( not_prefixed_key_len: u32, is_sum_tree: bool, ) -> u32
Encoded link size
sourcepub fn encoding_cost(&self) -> Result<usize>
pub fn encoding_cost(&self) -> Result<usize>
The encoding cost is always 8 bytes for the sum instead of a varint
Trait Implementations§
source§impl Encode for Link
impl Encode for Link
source§fn encode_into<W: Write>(&self, out: &mut W) -> Result<()>
fn encode_into<W: Write>(&self, out: &mut W) -> Result<()>
dest, or an
encoding error for types where invalid values are possible. Read moresource§fn encoding_length(&self) -> Result<usize>
fn encoding_length(&self) -> Result<usize>
impl StructuralPartialEq for Link
impl Terminated for Link
Auto Trait Implementations§
impl Freeze for Link
impl RefUnwindSafe for Link
impl Send for Link
impl Sync for Link
impl Unpin for Link
impl UnwindSafe for Link
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> CostsExt for T
impl<T> CostsExt for T
source§fn wrap_with_cost(self, cost: OperationCost) -> CostContext<Self>where
Self: Sized,
fn wrap_with_cost(self, cost: OperationCost) -> CostContext<Self>where
Self: Sized,
CostContext object with provided costs.source§fn wrap_fn_cost(
self,
f: impl FnOnce(&Self) -> OperationCost,
) -> CostContext<Self>where
Self: Sized,
fn wrap_fn_cost(
self,
f: impl FnOnce(&Self) -> OperationCost,
) -> CostContext<Self>where
Self: Sized,
CostContext object with costs computed using the
value getting wrapped.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