Struct grovedb_merk::tree::Walker

source ·
pub struct Walker<S>
where S: Fetch + Sized + Clone,
{ /* private fields */ }
Expand description

Allows traversal of a Tree, fetching from the given source when traversing to a pruned node, detaching children as they are traversed.

Implementations§

source§

impl<S> Walker<S>
where S: Fetch + Sized + Clone,

source

pub fn apply_to<K: AsRef<[u8]>, C, V, T, U, R>( maybe_tree: Option<Self>, batch: &MerkBatch<K>, source: S, old_tree_cost: &C, value_defined_cost_fn: Option<&V>, get_temp_new_value_with_old_flags: &T, update_tree_value_based_on_costs: &mut U, section_removal_bytes: &mut R, grove_version: &GroveVersion, ) -> CostContext<Result<(Option<TreeNode>, KeyUpdates), Error>>

Applies a batch of operations, possibly creating a new tree if maybe_tree is None. This is similar to Walker<S>::apply, but does not require a non-empty tree.

Keys in batch must be sorted and unique.

source

pub fn remove<V>( self, value_defined_cost_fn: Option<&V>, grove_version: &GroveVersion, ) -> CostResult<Option<Self>, Error>

Removes the root node from the tree. Rearranges and re-balances descendants (if any) in order to maintain a valid tree.

source§

impl<S> Walker<S>
where S: Fetch + Sized + Clone,

source

pub fn new(tree: TreeNode, source: S) -> Self

Creates a Walker with the given tree and source.

source

pub fn detach<V>( self, left: bool, value_defined_cost_fn: Option<&V>, grove_version: &GroveVersion, ) -> CostResult<(Self, Option<Self>), Error>

Similar to Tree#detach, but yields a Walker which fetches from the same source as self. Returned tuple is (updated_self, maybe_child_walker).

source

pub fn detach_expect<V>( self, left: bool, value_defined_cost_fn: Option<&V>, grove_version: &GroveVersion, ) -> CostResult<(Self, Self), Error>

Similar to Tree#detach_expect, but yields a Walker which fetches from the same source as self. Returned tuple is (updated_self, child_walker).

source

pub fn walk<F, T, V>( self, left: bool, f: F, value_defined_cost_fn: Option<&V>, grove_version: &GroveVersion, ) -> CostResult<Self, Error>

Similar to Tree#walk, but yields a Walker which fetches from the same source as self.

source

pub fn walk_expect<F, T, V>( self, left: bool, f: F, value_defined_cost_fn: Option<&V>, grove_version: &GroveVersion, ) -> CostResult<Self, Error>

Similar to Tree#walk_expect but yields a Walker which fetches from the same source as self.

source

pub fn tree(&self) -> &TreeNode

Returns an immutable reference to the Tree wrapped by this walker.

source

pub fn into_inner(self) -> TreeNode

Consumes the Walker and returns the Tree it wraps.

source

pub fn clone_source(&self) -> S

Returns a clone of this Walker’s source.

source

pub fn attach<T>(self, left: bool, maybe_child: Option<T>) -> Self
where T: Into<TreeNode>,

Similar to Tree#attach, but can also take a Walker since it implements Into<Tree>.

source

pub fn put_value( self, value: Vec<u8>, feature_type: TreeFeatureType, old_specialized_cost: &impl Fn(&Vec<u8>, &Vec<u8>) -> Result<u32, Error>, get_temp_new_value_with_old_flags: &impl Fn(&Vec<u8>, &Vec<u8>) -> Result<Option<Vec<u8>>, Error>, update_tree_value_based_on_costs: &mut impl FnMut(&StorageCost, &Vec<u8>, &mut Vec<u8>) -> Result<(bool, Option<ValueDefinedCostType>), Error>, section_removal_bytes: &mut impl FnMut(&Vec<u8>, u32, u32) -> Result<(StorageRemovedBytes, StorageRemovedBytes), Error>, ) -> CostResult<Self, Error>

Similar to Tree#put_value.

source

pub fn put_value_with_fixed_cost( self, value: Vec<u8>, value_fixed_cost: u32, feature_type: TreeFeatureType, old_specialized_cost: &impl Fn(&Vec<u8>, &Vec<u8>) -> Result<u32, Error>, get_temp_new_value_with_old_flags: &impl Fn(&Vec<u8>, &Vec<u8>) -> Result<Option<Vec<u8>>, Error>, update_tree_value_based_on_costs: &mut impl FnMut(&StorageCost, &Vec<u8>, &mut Vec<u8>) -> Result<(bool, Option<ValueDefinedCostType>), Error>, section_removal_bytes: &mut impl FnMut(&Vec<u8>, u32, u32) -> Result<(StorageRemovedBytes, StorageRemovedBytes), Error>, ) -> CostResult<Self, Error>

Similar to Tree#put_value_with_fixed_cost.

source

pub fn put_value_and_reference_value_hash( self, value: Vec<u8>, value_hash: CryptoHash, feature_type: TreeFeatureType, old_specialized_cost: &impl Fn(&Vec<u8>, &Vec<u8>) -> Result<u32, Error>, get_temp_new_value_with_old_flags: &impl Fn(&Vec<u8>, &Vec<u8>) -> Result<Option<Vec<u8>>, Error>, update_tree_value_based_on_costs: &mut impl FnMut(&StorageCost, &Vec<u8>, &mut Vec<u8>) -> Result<(bool, Option<ValueDefinedCostType>), Error>, section_removal_bytes: &mut impl FnMut(&Vec<u8>, u32, u32) -> Result<(StorageRemovedBytes, StorageRemovedBytes), Error>, ) -> CostResult<Self, Error>

Similar to Tree#put_value_and_reference_value_hash.

source

pub fn put_value_with_reference_value_hash_and_value_cost( self, value: Vec<u8>, value_hash: CryptoHash, value_fixed_cost: u32, feature_type: TreeFeatureType, old_specialized_cost: &impl Fn(&Vec<u8>, &Vec<u8>) -> Result<u32, Error>, get_temp_new_value_with_old_flags: &impl Fn(&Vec<u8>, &Vec<u8>) -> Result<Option<Vec<u8>>, Error>, update_tree_value_based_on_costs: &mut impl FnMut(&StorageCost, &Vec<u8>, &mut Vec<u8>) -> Result<(bool, Option<ValueDefinedCostType>), Error>, section_removal_bytes: &mut impl FnMut(&Vec<u8>, u32, u32) -> Result<(StorageRemovedBytes, StorageRemovedBytes), Error>, ) -> CostResult<Self, Error>

Similar to Tree#put_value_with_reference_value_hash_and_value_cost.

Trait Implementations§

source§

impl<S> From<Walker<S>> for TreeNode
where S: Fetch + Sized + Clone,

source§

fn from(walker: Walker<S>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S> Freeze for Walker<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Walker<S>
where S: RefUnwindSafe,

§

impl<S> Send for Walker<S>
where S: Send,

§

impl<S> Sync for Walker<S>
where S: Sync,

§

impl<S> Unpin for Walker<S>
where S: Unpin,

§

impl<S> UnwindSafe for Walker<S>
where S: 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> 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, 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