pub struct Tree<Root: Root, File: ManagedFile> { /* private fields */ }Expand description
A named collection of keys and values.
Implementations
sourceimpl<Root: Root, File: ManagedFile> Tree<Root, File>
impl<Root: Root, File: ManagedFile> Tree<Root, File>
sourcepub fn count(&self) -> u64
pub fn count(&self) -> u64
Returns the number of keys stored in the tree. Does not include deleted keys.
sourcepub fn set(
&self,
key: impl Into<ArcBytes<'static>>,
value: impl Into<ArcBytes<'static>>
) -> Result<(), Error>
pub fn set(
&self,
key: impl Into<ArcBytes<'static>>,
value: impl Into<ArcBytes<'static>>
) -> Result<(), Error>
Sets key to value. This is executed within its own transaction.
sourcepub fn get(&self, key: &[u8]) -> Result<Option<ArcBytes<'static>>, Error>
pub fn get(&self, key: &[u8]) -> Result<Option<ArcBytes<'static>>, Error>
Retrieves the current value of key, if present. Does not reflect any
changes in pending transactions.
sourcepub fn replace(
&mut self,
key: impl Into<ArcBytes<'static>>,
value: impl Into<ArcBytes<'static>>
) -> Result<Option<ArcBytes<'static>>, Error>
pub fn replace(
&mut self,
key: impl Into<ArcBytes<'static>>,
value: impl Into<ArcBytes<'static>>
) -> Result<Option<ArcBytes<'static>>, Error>
Sets key to value. If a value already exists, it will be returned.
sourcepub fn modify<'a>(
&mut self,
keys: Vec<ArcBytes<'a>>,
operation: Operation<'a, ArcBytes<'static>>
) -> Result<(), Error>
pub fn modify<'a>(
&mut self,
keys: Vec<ArcBytes<'a>>,
operation: Operation<'a, ArcBytes<'static>>
) -> Result<(), Error>
Executes a modification.
sourcepub fn remove(&self, key: &[u8]) -> Result<Option<ArcBytes<'static>>, Error>
pub fn remove(&self, key: &[u8]) -> Result<Option<ArcBytes<'static>>, Error>
Removes key and returns the existing value, if present. This is executed within its own transaction.
sourcepub fn compare_and_swap(
&self,
key: &[u8],
old: Option<&[u8]>,
new: Option<ArcBytes<'_>>
) -> Result<(), CompareAndSwapError>
pub fn compare_and_swap(
&self,
key: &[u8],
old: Option<&[u8]>,
new: Option<ArcBytes<'_>>
) -> Result<(), CompareAndSwapError>
Compares the value of key against old. If the values match, key will
be set to the new value if new is Some or removed if new is
None. This is executed within its own transaction.
sourcepub fn get_multiple<'keys, Keys>(
&self,
keys: Keys
) -> Result<Vec<(ArcBytes<'static>, ArcBytes<'static>)>, Error> where
Keys: Iterator<Item = &'keys [u8]> + ExactSizeIterator + Clone,
pub fn get_multiple<'keys, Keys>(
&self,
keys: Keys
) -> Result<Vec<(ArcBytes<'static>, ArcBytes<'static>)>, Error> where
Keys: Iterator<Item = &'keys [u8]> + ExactSizeIterator + Clone,
Retrieves the values of keys. If any keys are not found, they will be
omitted from the results. Keys are required to be pre-sorted.
sourcepub fn get_range<'keys, KeyRangeBounds>(
&self,
range: &'keys KeyRangeBounds
) -> Result<Vec<(ArcBytes<'static>, ArcBytes<'static>)>, Error> where
KeyRangeBounds: RangeBounds<&'keys [u8]> + Debug + Clone + ?Sized,
pub fn get_range<'keys, KeyRangeBounds>(
&self,
range: &'keys KeyRangeBounds
) -> Result<Vec<(ArcBytes<'static>, ArcBytes<'static>)>, Error> where
KeyRangeBounds: RangeBounds<&'keys [u8]> + Debug + Clone + ?Sized,
Retrieves all of the values of keys within range.
sourcepub fn scan<'keys, CallerError, KeyRangeBounds, NodeEvaluator, KeyEvaluator, DataCallback>(
&self,
range: &'keys KeyRangeBounds,
forwards: bool,
node_evaluator: NodeEvaluator,
key_evaluator: KeyEvaluator,
callback: DataCallback
) -> Result<(), AbortError<CallerError>> where
KeyRangeBounds: RangeBounds<&'keys [u8]> + Debug + Clone + ?Sized,
NodeEvaluator: FnMut(&ArcBytes<'static>, &Root::ReducedIndex, usize) -> ScanEvaluation,
KeyEvaluator: FnMut(&ArcBytes<'static>, &Root::Index) -> ScanEvaluation,
DataCallback: FnMut(ArcBytes<'static>, &Root::Index, ArcBytes<'static>) -> Result<(), AbortError<CallerError>>,
CallerError: Display + Debug,
pub fn scan<'keys, CallerError, KeyRangeBounds, NodeEvaluator, KeyEvaluator, DataCallback>(
&self,
range: &'keys KeyRangeBounds,
forwards: bool,
node_evaluator: NodeEvaluator,
key_evaluator: KeyEvaluator,
callback: DataCallback
) -> Result<(), AbortError<CallerError>> where
KeyRangeBounds: RangeBounds<&'keys [u8]> + Debug + Clone + ?Sized,
NodeEvaluator: FnMut(&ArcBytes<'static>, &Root::ReducedIndex, usize) -> ScanEvaluation,
KeyEvaluator: FnMut(&ArcBytes<'static>, &Root::Index) -> ScanEvaluation,
DataCallback: FnMut(ArcBytes<'static>, &Root::Index, ArcBytes<'static>) -> Result<(), AbortError<CallerError>>,
CallerError: Display + Debug,
Scans the tree across all nodes that might contain nodes within range.
If forwards is true, the tree is scanned in ascending order.
Otherwise, the tree is scanned in descending order.
node_evaluator is invoked for each Interior node to determine if
the node should be traversed. The parameters to the callback are:
&ArcBytes<'static>: The maximum key stored within the all children nodes.&Root::ReducedIndex: The reduced index value stored within the node.usize: The depth of the node. The root nodes are depth 0.
The result of the callback is a ScanEvaluation. To read children
nodes, return ScanEvaluation::ReadData.
key_evaluator is invoked for each key encountered that is contained
within range. For all ScanEvaluation::ReadData results returned,
callback will be invoked with the key and values. callback may not
be invoked in the same order as the keys are scanned.
sourcepub fn reduce<'keys, KeyRangeBounds>(
&self,
range: &'keys KeyRangeBounds
) -> Result<Root::ReducedIndex, Error> where
KeyRangeBounds: RangeBounds<&'keys [u8]> + Debug + Clone + ?Sized,
pub fn reduce<'keys, KeyRangeBounds>(
&self,
range: &'keys KeyRangeBounds
) -> Result<Root::ReducedIndex, Error> where
KeyRangeBounds: RangeBounds<&'keys [u8]> + Debug + Clone + ?Sized,
Returns the reduced index over the provided range. This is an
aggregation function that builds atop the scan() operation which calls
Reducer::reduce() and Reducer::rereduce() on all matching
indexes stored within the nodes of this tree, producing a single
aggregated Root::ReducedIndex value.
If no keys match, the returned result is what Reducer::rereduce()
returns when an empty slice is provided.
sourcepub fn first_key(&self) -> Result<Option<ArcBytes<'static>>, Error>
pub fn first_key(&self) -> Result<Option<ArcBytes<'static>>, Error>
Returns the first key of the tree.
sourcepub fn first(
&self
) -> Result<Option<(ArcBytes<'static>, ArcBytes<'static>)>, Error>
pub fn first(
&self
) -> Result<Option<(ArcBytes<'static>, ArcBytes<'static>)>, Error>
Returns the first key and value of the tree.
sourcepub fn last_key(&self) -> Result<Option<ArcBytes<'static>>, Error>
pub fn last_key(&self) -> Result<Option<ArcBytes<'static>>, Error>
Returns the last key of the tree.
sourceimpl<File: ManagedFile, Index> Tree<VersionedTreeRoot<Index>, File> where
Index: EmbeddedIndex + Reducer<Index> + Clone + Debug + 'static,
impl<File: ManagedFile, Index> Tree<VersionedTreeRoot<Index>, File> where
Index: EmbeddedIndex + Reducer<Index> + Clone + Debug + 'static,
sourcepub fn scan_sequences<CallerError, Range, KeyEvaluator, DataCallback>(
&mut self,
range: Range,
forwards: bool,
key_evaluator: &mut KeyEvaluator,
data_callback: &mut DataCallback
) -> Result<(), AbortError<CallerError>> where
Range: Clone + RangeBounds<u64> + Debug + 'static,
KeyEvaluator: FnMut(KeySequence) -> ScanEvaluation,
DataCallback: FnMut(KeySequence, ArcBytes<'static>) -> Result<(), AbortError<CallerError>>,
CallerError: Display + Debug,
pub fn scan_sequences<CallerError, Range, KeyEvaluator, DataCallback>(
&mut self,
range: Range,
forwards: bool,
key_evaluator: &mut KeyEvaluator,
data_callback: &mut DataCallback
) -> Result<(), AbortError<CallerError>> where
Range: Clone + RangeBounds<u64> + Debug + 'static,
KeyEvaluator: FnMut(KeySequence) -> ScanEvaluation,
DataCallback: FnMut(KeySequence, ArcBytes<'static>) -> Result<(), AbortError<CallerError>>,
CallerError: Display + Debug,
Scans the tree for keys that are contained within range. If forwards
is true, scanning starts at the lowest sort-order key and scans forward.
Otherwise, scanning starts at the highest sort-order key and scans
backwards. key_evaluator is invoked for each key as it is encountered.
For all ScanEvaluation::ReadData results returned, callback will be
invoked with the key and values. The callback may not be invoked in the
same order as the keys are scanned.
Trait Implementations
sourceimpl<Root: Root, File: ManagedFile> AnyTreeRoot<File> for Tree<Root, File>
impl<Root: Root, File: ManagedFile> AnyTreeRoot<File> for Tree<Root, File>
sourcefn default_state(&self) -> Box<dyn AnyTreeState>
fn default_state(&self) -> Box<dyn AnyTreeState>
The default state for the underlying root type.
Auto Trait Implementations
impl<Root, File> !RefUnwindSafe for Tree<Root, File>
impl<Root, File> Send for Tree<Root, File>
impl<Root, File> Sync for Tree<Root, File>
impl<Root, File> Unpin for Tree<Root, File>
impl<Root, File> !UnwindSafe for Tree<Root, File>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more