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 get_index(&self, key: &[u8]) -> Result<Option<Root::Index>, Error>
pub fn get_index(&self, key: &[u8]) -> Result<Option<Root::Index>, Error>
Retrieves the current index of key
, if present. Does not reflect any
changes in pending transactions.
sourcepub fn get_with_index(
&self,
key: &[u8]
) -> Result<Option<(ArcBytes<'static>, Root::Index)>, Error>
pub fn get_with_index(
&self,
key: &[u8]
) -> Result<Option<(ArcBytes<'static>, Root::Index)>, Error>
Retrieves the current value and index 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>>, Root::Index), Error>
pub fn replace(
&mut self,
key: impl Into<ArcBytes<'static>>,
value: impl Into<ArcBytes<'static>>
) -> Result<(Option<ArcBytes<'static>>, Root::Index), Error>
Sets key
to value
. Returns a tuple containing two elements:
- The previously stored value, if a value was already present.
- The new/updated index for this key.
sourcepub fn modify<'a>(
&mut self,
keys: Vec<ArcBytes<'a>>,
operation: Operation<'a, ArcBytes<'static>, Root::Index>
) -> Result<Vec<ModificationResult<Root::Index>>, Error>
pub fn modify<'a>(
&mut self,
keys: Vec<ArcBytes<'a>>,
operation: Operation<'a, ArcBytes<'static>, Root::Index>
) -> Result<Vec<ModificationResult<Root::Index>>, Error>
Executes a modification. Returns a list of all changed keys.
sourcepub fn remove(
&self,
key: &[u8]
) -> Result<Option<(ArcBytes<'static>, Root::Index)>, Error>
pub fn remove(
&self,
key: &[u8]
) -> Result<Option<(ArcBytes<'static>, Root::Index)>, Error>
Removes key
and returns the existing value and index, 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_multiple_indexes<'keys, KeysIntoIter, KeysIter>(
&self,
keys: KeysIntoIter
) -> Result<Vec<(ArcBytes<'static>, Root::Index)>, Error> where
KeysIntoIter: IntoIterator<Item = &'keys [u8], IntoIter = KeysIter> + Clone,
KeysIter: Iterator<Item = &'keys [u8]> + ExactSizeIterator,
pub fn get_multiple_indexes<'keys, KeysIntoIter, KeysIter>(
&self,
keys: KeysIntoIter
) -> Result<Vec<(ArcBytes<'static>, Root::Index)>, Error> where
KeysIntoIter: IntoIterator<Item = &'keys [u8], IntoIter = KeysIter> + Clone,
KeysIter: Iterator<Item = &'keys [u8]> + ExactSizeIterator,
Retrieves the indexes 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_multiple_with_indexes<'keys, KeysIntoIter, KeysIter>(
&self,
keys: KeysIntoIter
) -> Result<Vec<(ArcBytes<'static>, ArcBytes<'static>, Root::Index)>, Error> where
KeysIntoIter: IntoIterator<Item = &'keys [u8], IntoIter = KeysIter> + Clone,
KeysIter: Iterator<Item = &'keys [u8]> + ExactSizeIterator,
pub fn get_multiple_with_indexes<'keys, KeysIntoIter, KeysIter>(
&self,
keys: KeysIntoIter
) -> Result<Vec<(ArcBytes<'static>, ArcBytes<'static>, Root::Index)>, Error> where
KeysIntoIter: IntoIterator<Item = &'keys [u8], IntoIter = KeysIter> + Clone,
KeysIter: Iterator<Item = &'keys [u8]> + ExactSizeIterator,
Retrieves the values and indexes 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 get_range_indexes<'keys, KeyRangeBounds>(
&self,
range: &'keys KeyRangeBounds
) -> Result<Vec<(ArcBytes<'static>, Root::Index)>, Error> where
KeyRangeBounds: RangeBounds<&'keys [u8]> + Debug + ?Sized,
pub fn get_range_indexes<'keys, KeyRangeBounds>(
&self,
range: &'keys KeyRangeBounds
) -> Result<Vec<(ArcBytes<'static>, Root::Index)>, Error> where
KeyRangeBounds: RangeBounds<&'keys [u8]> + Debug + ?Sized,
Retrieves all of the indexes of keys within range
.
sourcepub fn get_range_with_indexes<'keys, KeyRangeBounds>(
&self,
range: &'keys KeyRangeBounds
) -> Result<Vec<(ArcBytes<'static>, ArcBytes<'static>, Root::Index)>, Error> where
KeyRangeBounds: RangeBounds<&'keys [u8]> + Debug + ?Sized,
pub fn get_range_with_indexes<'keys, KeyRangeBounds>(
&self,
range: &'keys KeyRangeBounds
) -> Result<Vec<(ArcBytes<'static>, ArcBytes<'static>, Root::Index)>, Error> where
KeyRangeBounds: RangeBounds<&'keys [u8]> + Debug + ?Sized,
Retrieves all of the values and indexes 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<Option<Root::ReducedIndex>, Error> where
KeyRangeBounds: RangeBounds<&'keys [u8]> + Debug + Clone + ?Sized,
pub fn reduce<'keys, KeyRangeBounds>(
&self,
range: &'keys KeyRangeBounds
) -> Result<Option<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 + Clone + Debug + 'static,
impl<File: ManagedFile, Index> Tree<VersionedTreeRoot<Index>, File> where
Index: EmbeddedIndex + Clone + Debug + 'static,
sourcepub fn current_sequence_id(&self) -> SequenceId
pub fn current_sequence_id(&self) -> SequenceId
Returns the latest sequence id.
sourcepub fn scan_sequences<CallerError, Range, KeyEvaluator, DataCallback>(
&self,
range: Range,
forwards: bool,
key_evaluator: &mut KeyEvaluator,
data_callback: &mut DataCallback
) -> Result<(), AbortError<CallerError>> where
Range: Clone + RangeBounds<SequenceId> + Debug + 'static,
KeyEvaluator: FnMut(KeySequence<Index>) -> ScanEvaluation,
DataCallback: FnMut(KeySequence<Index>, ArcBytes<'static>) -> Result<(), AbortError<CallerError>>,
CallerError: Display + Debug,
pub fn scan_sequences<CallerError, Range, KeyEvaluator, DataCallback>(
&self,
range: Range,
forwards: bool,
key_evaluator: &mut KeyEvaluator,
data_callback: &mut DataCallback
) -> Result<(), AbortError<CallerError>> where
Range: Clone + RangeBounds<SequenceId> + Debug + 'static,
KeyEvaluator: FnMut(KeySequence<Index>) -> ScanEvaluation,
DataCallback: FnMut(KeySequence<Index>, 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.
sourcepub fn get_multiple_by_sequence<Sequences>(
&mut self,
sequences: Sequences
) -> Result<HashMap<SequenceId, (ArcBytes<'static>, Option<ArcBytes<'static>>)>, Error> where
Sequences: Iterator<Item = SequenceId> + Clone,
pub fn get_multiple_by_sequence<Sequences>(
&mut self,
sequences: Sequences
) -> Result<HashMap<SequenceId, (ArcBytes<'static>, Option<ArcBytes<'static>>)>, Error> where
Sequences: Iterator<Item = SequenceId> + Clone,
Retrieves the keys and values associated with one or more sequences
.
The value retrieved is the value of the key at the given SequenceId
.
If a sequence is not found, it will not appear in the result map. If
the value was removed, None is returned for the value.
sourcepub fn get_multiple_indexes_by_sequence<Sequences>(
&mut self,
sequences: Sequences
) -> Result<Vec<SequenceIndex<Index>>, Error> where
Sequences: Iterator<Item = SequenceId> + Clone,
pub fn get_multiple_indexes_by_sequence<Sequences>(
&mut self,
sequences: Sequences
) -> Result<Vec<SequenceIndex<Index>>, Error> where
Sequences: Iterator<Item = SequenceId> + Clone,
Retrieves the keys and indexes associated with one or more sequences
.
The value retrieved is the value of the key at the given SequenceId
.
If a sequence is not found, it will not appear in the result list.
sourcepub fn get_multiple_with_indexes_by_sequence<Sequences>(
&mut self,
sequences: Sequences
) -> Result<HashMap<SequenceId, SequenceEntry<Index>>, Error> where
Sequences: Iterator<Item = SequenceId> + Clone,
pub fn get_multiple_with_indexes_by_sequence<Sequences>(
&mut self,
sequences: Sequences
) -> Result<HashMap<SequenceId, SequenceEntry<Index>>, Error> where
Sequences: Iterator<Item = SequenceId> + Clone,
Retrieves the keys, values, and indexes associated with one or more
sequences
. The value retrieved is the value of the key at the given
SequenceId
. If a sequence is not found, it will not appear in the
result list.
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.
sourcefn begin_transaction(
&self,
transaction_id: TransactionId,
file_path: &Path,
state: &dyn AnyTreeState,
context: &Context<File::Manager>,
transactions: Option<&TransactionManager<File::Manager>>
) -> Result<Box<dyn AnyTransactionTree<File>>, Error>
fn begin_transaction(
&self,
transaction_id: TransactionId,
file_path: &Path,
state: &dyn AnyTreeState,
context: &Context<File::Manager>,
transactions: Option<&TransactionManager<File::Manager>>
) -> Result<Box<dyn AnyTransactionTree<File>>, Error>
Begins a transaction on this tree.
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 · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more