Tree

Struct Tree 

Source
pub struct Tree<Root: Root, File: ManagedFile> { /* private fields */ }
Expand description

A named collection of keys and values.

Implementations§

Source§

impl<Root: Root, File: ManagedFile> Tree<Root, File>

Source

pub fn name(&self) -> &str

Returns the name of the tree.

Source

pub fn path(&self) -> PathBuf

Returns the path to the file for this tree.

Source

pub fn count(&self) -> u64

Returns the number of keys stored in the tree. Does not include deleted keys.

Source

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.

Source

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.

Source

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.

Source

pub fn modify<'a>( &mut self, keys: Vec<ArcBytes<'a>>, operation: Operation<'a, ArcBytes<'static>>, ) -> Result<(), Error>

Executes a modification.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn first_key(&self) -> Result<Option<ArcBytes<'static>>, Error>

Returns the first key of the tree.

Source

pub fn first( &self, ) -> Result<Option<(ArcBytes<'static>, ArcBytes<'static>)>, Error>

Returns the first key and value of the tree.

Source

pub fn last_key(&self) -> Result<Option<ArcBytes<'static>>, Error>

Returns the last key of the tree.

Source

pub fn last( &self, ) -> Result<Option<(ArcBytes<'static>, ArcBytes<'static>)>, Error>

Returns the last key and value of the tree.

Source

pub fn compact(&self) -> Result<(), Error>

Rewrites the database to remove data that is no longer current. Because Nebari uses an append-only format, this is helpful in reducing disk usage.

See TreeFile::compact() for more information.

Source§

impl<File: ManagedFile, Index> Tree<VersionedTreeRoot<Index>, File>
where Index: EmbeddedIndex + Reducer<Index> + Clone + Debug + 'static,

Source

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§

Source§

impl<Root: Root, File: ManagedFile> AnyTreeRoot<File> for Tree<Root, File>

Source§

fn name(&self) -> &str

The name of the tree.
Source§

fn default_state(&self) -> Box<dyn AnyTreeState>

The default state for the underlying root type.
Source§

fn begin_transaction( &self, transaction_id: u64, 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.
Source§

impl<Root: Root, File: ManagedFile> Clone for Tree<Root, File>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<Root, File> Freeze for Tree<Root, File>

§

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§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.