pub struct Tree<V, E, F> { /* private fields */ }
Expand description
A flash-sympathetic persistent lock-free B+ tree
This tree keeps track of insert and update times if requested
Implementations§
Source§impl<V, E, F> ExpiringTree<V, E, F>
impl<V, E, F> ExpiringTree<V, E, F>
Sourcepub fn transaction<G, R>(&self, g: G) -> TransactionResult<Result<R>>
pub fn transaction<G, R>(&self, g: G) -> TransactionResult<Result<R>>
Perform a multi-key serializable transaction.
Transactions also work on tuples of Trees, preserving serializable ACID semantics! In this example, we treat two trees like a work queue, atomically apply updates to data and move them from the unprocessed Tree to the processed Tree.
Sourcepub fn apply_batch(&self, batch: ExpiringBatch<V, F>) -> Result<()>
pub fn apply_batch(&self, batch: ExpiringBatch<V, F>) -> Result<()>
Create a new batched update that can be atomically applied.
It is possible to apply a Batch in a transaction as well, which is the way you can apply a Batch to multiple Trees atomically.
Sourcepub fn compare_and_swap<K>(
&self,
key: K,
old: Option<V>,
new: Option<V>,
) -> Result<Result<(), CompareAndSwapError<V>>>
pub fn compare_and_swap<K>( &self, key: K, old: Option<V>, new: Option<V>, ) -> Result<Result<(), CompareAndSwapError<V>>>
Compare and swap. Capable of unique creation, conditional modification, or deletion. If old is None, this will only set the value if it doesn’t exist yet. If new is None, will delete the value if old is correct. If both old and new are Some, will modify the value if old is correct.
It returns Ok(Ok(())) if operation finishes successfully.
If it fails it returns: - Ok(Err(CompareAndSwapError(current, proposed))) if operation failed to setup a new value. CompareAndSwapError contains current and proposed values.
- Err(Error::Unsupported) if the database is opened in read-only mode.
Sourcepub fn insert<K>(&self, key: K, value: V) -> Result<Option<V>>
pub fn insert<K>(&self, key: K, value: V) -> Result<Option<V>>
Insert a key to a new value, returning the last value if it was set.
Sourcepub fn remove<K>(&self, key: K) -> Result<Option<V>>
pub fn remove<K>(&self, key: K) -> Result<Option<V>>
Delete a value, returning the old value if it existed.
Sourcepub fn update_and_fetch<K>(
&self,
key: K,
f: impl Fn(Option<V>) -> Option<V>,
) -> Result<Option<V>>
pub fn update_and_fetch<K>( &self, key: K, f: impl Fn(Option<V>) -> Option<V>, ) -> Result<Option<V>>
Fetch the value, apply a function to it and return the result.
§Note
This may call the function multiple times if the value has been changed from other threads in the meantime.
Sourcepub fn fetch_and_update<K>(
&self,
key: K,
f: impl Fn(Option<V>) -> Option<V>,
) -> Result<Option<V>>
pub fn fetch_and_update<K>( &self, key: K, f: impl Fn(Option<V>) -> Option<V>, ) -> Result<Option<V>>
Fetch the value, apply a function to it and return the previous value.
§Note
This may call the function multiple times if the value has been changed from other threads in the meantime.
Sourcepub fn flush(&self) -> Result<()>
pub fn flush(&self) -> Result<()>
Synchronously flushes all dirty IO buffers and calls fsync. If this succeeds, it is guaranteed that all previous writes will be recovered if the system crashes. Returns the number of bytes flushed during this call.
Flushing can take quite a lot of time, and you should measure the performance impact of using it on realistic sustained workloads running on realistic hardware.
Sourcepub fn contains_key<K>(&self, key: K) -> Result<bool>
pub fn contains_key<K>(&self, key: K) -> Result<bool>
Returns true
if the Tree
contains a value for the specified key.
Sourcepub fn iter<'a>(&'a self) -> ExpiringIter<'a, V, E, F> ⓘ
pub fn iter<'a>(&'a self) -> ExpiringIter<'a, V, E, F> ⓘ
Create a double-ended iterator over the tuples of keys and values in this tree.
Sourcepub fn range<'a, K, R>(&'a self, range: R) -> ExpiringIter<'a, V, E, F> ⓘ
pub fn range<'a, K, R>(&'a self, range: R) -> ExpiringIter<'a, V, E, F> ⓘ
Create a double-ended iterator over tuples of keys and values, where the keys fall within the specified range.
Sourcepub fn get_lt<K>(&self, key: K) -> Result<Option<(IVec, V)>>
pub fn get_lt<K>(&self, key: K) -> Result<Option<(IVec, V)>>
Retrieve the key and value before the provided key, if one exists.
Sourcepub fn get_gt<K>(&self, key: K) -> Result<Option<(IVec, V)>>
pub fn get_gt<K>(&self, key: K) -> Result<Option<(IVec, V)>>
Retrieve the next key and value from the Tree after the provided key.
§Note
The order follows the Ord implementation for Vec
[] < [0] < [255] < [255, 0] < [255, 255] ...
To retain the ordering of numerical types use big endian reprensentation
Sourcepub fn scan_prefix<'a, P>(&'a self, prefix: P) -> ExpiringIter<'a, V, E, F> ⓘ
pub fn scan_prefix<'a, P>(&'a self, prefix: P) -> ExpiringIter<'a, V, E, F> ⓘ
Create an iterator over tuples of keys and values, where the all the keys starts with the given prefix.
Sourcepub fn pop_max(&self) -> Result<Option<(IVec, V)>>
pub fn pop_max(&self) -> Result<Option<(IVec, V)>>
Atomically removes the maximum item in the Tree
instance.
Sourcepub fn pop_min(&self) -> Result<Option<(IVec, V)>>
pub fn pop_min(&self) -> Result<Option<(IVec, V)>>
Atomically removes the minimum item in the Tree
instance.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in this tree.
Beware: performs a full O(n) scan under the hood.