Struct grovedb_merk::tree::Walker
source · pub struct Walker<S>{ /* 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>
impl<S> Walker<S>
sourcepub 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>>where
C: Fn(&Vec<u8>, &Vec<u8>) -> Result<u32, Error>,
V: Fn(&[u8], &GroveVersion) -> Option<ValueDefinedCostType>,
T: Fn(&Vec<u8>, &Vec<u8>) -> Result<Option<Vec<u8>>, Error>,
U: FnMut(&StorageCost, &Vec<u8>, &mut Vec<u8>) -> Result<(bool, Option<ValueDefinedCostType>), Error>,
R: FnMut(&Vec<u8>, u32, u32) -> Result<(StorageRemovedBytes, StorageRemovedBytes), Error>,
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>>where
C: Fn(&Vec<u8>, &Vec<u8>) -> Result<u32, Error>,
V: Fn(&[u8], &GroveVersion) -> Option<ValueDefinedCostType>,
T: Fn(&Vec<u8>, &Vec<u8>) -> Result<Option<Vec<u8>>, Error>,
U: FnMut(&StorageCost, &Vec<u8>, &mut Vec<u8>) -> Result<(bool, Option<ValueDefinedCostType>), Error>,
R: FnMut(&Vec<u8>, u32, u32) -> Result<(StorageRemovedBytes, StorageRemovedBytes), 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.
sourcepub fn remove<V>(
self,
value_defined_cost_fn: Option<&V>,
grove_version: &GroveVersion,
) -> CostResult<Option<Self>, Error>
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>
impl<S> Walker<S>
sourcepub fn detach<V>(
self,
left: bool,
value_defined_cost_fn: Option<&V>,
grove_version: &GroveVersion,
) -> CostResult<(Self, Option<Self>), Error>
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).
sourcepub fn detach_expect<V>(
self,
left: bool,
value_defined_cost_fn: Option<&V>,
grove_version: &GroveVersion,
) -> CostResult<(Self, Self), Error>
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).
sourcepub fn walk<F, T, V>(
self,
left: bool,
f: F,
value_defined_cost_fn: Option<&V>,
grove_version: &GroveVersion,
) -> CostResult<Self, Error>where
F: FnOnce(Option<Self>) -> CostResult<Option<T>, Error>,
T: Into<TreeNode>,
V: Fn(&[u8], &GroveVersion) -> Option<ValueDefinedCostType>,
pub fn walk<F, T, V>(
self,
left: bool,
f: F,
value_defined_cost_fn: Option<&V>,
grove_version: &GroveVersion,
) -> CostResult<Self, Error>where
F: FnOnce(Option<Self>) -> CostResult<Option<T>, Error>,
T: Into<TreeNode>,
V: Fn(&[u8], &GroveVersion) -> Option<ValueDefinedCostType>,
Similar to Tree#walk, but yields a Walker which fetches from the
same source as self.
sourcepub fn walk_expect<F, T, V>(
self,
left: bool,
f: F,
value_defined_cost_fn: Option<&V>,
grove_version: &GroveVersion,
) -> CostResult<Self, Error>where
F: FnOnce(Self) -> CostResult<Option<T>, Error>,
T: Into<TreeNode>,
V: Fn(&[u8], &GroveVersion) -> Option<ValueDefinedCostType>,
pub fn walk_expect<F, T, V>(
self,
left: bool,
f: F,
value_defined_cost_fn: Option<&V>,
grove_version: &GroveVersion,
) -> CostResult<Self, Error>where
F: FnOnce(Self) -> CostResult<Option<T>, Error>,
T: Into<TreeNode>,
V: Fn(&[u8], &GroveVersion) -> Option<ValueDefinedCostType>,
Similar to Tree#walk_expect but yields a Walker which fetches from
the same source as self.
sourcepub fn tree(&self) -> &TreeNode
pub fn tree(&self) -> &TreeNode
Returns an immutable reference to the Tree wrapped by this walker.
sourcepub fn into_inner(self) -> TreeNode
pub fn into_inner(self) -> TreeNode
Consumes the Walker and returns the Tree it wraps.
sourcepub fn clone_source(&self) -> S
pub fn clone_source(&self) -> S
Returns a clone of this Walker’s source.
sourcepub fn attach<T>(self, left: bool, maybe_child: Option<T>) -> Self
pub fn attach<T>(self, left: bool, maybe_child: Option<T>) -> Self
Similar to Tree#attach, but can also take a Walker since it
implements Into<Tree>.
sourcepub 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>
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.
sourcepub 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>
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.
sourcepub 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>
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.
sourcepub 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>
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§
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> 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> 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