Struct Tree

Source
pub struct Tree { /* private fields */ }
Expand description

atomic lock-free tree A flash-sympathetic persistent lock-free B+ tree

Implementations§

Source§

impl Tree

Source

pub fn new(config: Config) -> Tree

Load existing or create a new Tree.

Source

pub fn config(&self) -> &Config

Returns a ref to the current Config in use by the system.

Source

pub fn get(&self, key: &[u8]) -> Option<Vec<u8>>

Retrieve a value from the Tree if it exists.

Source

pub fn cas( &self, key: Vec<u8>, old: Option<Vec<u8>>, new: Option<Vec<u8>>, ) -> Result<(), Option<Vec<u8>>>

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.

§Examples
use rsdb::Config;
let t = Config::default().tree();

// unique creation
assert_eq!(t.cas(vec![1], None, Some(vec![1])), Ok(()));
assert_eq!(t.cas(vec![1], None, Some(vec![1])), Err(Some(vec![1])));

// conditional modification
assert_eq!(t.cas(vec![1], Some(vec![1]), Some(vec![2])), Ok(()));
assert_eq!(t.cas(vec![1], Some(vec![1]), Some(vec![2])), Err(Some(vec![2])));

// conditional deletion
assert_eq!(t.cas(vec![1], Some(vec![2]), None), Ok(()));
assert_eq!(t.get(&*vec![1]), None);
Source

pub fn set(&self, key: Vec<u8>, value: Vec<u8>)

Set a key to a new value.

Source

pub fn del(&self, key: &[u8]) -> Option<Vec<u8>>

Delete a value, returning the last result if it existed.

§Examples
use rsdb::Config;
let t = Config::default().tree();
t.set(vec![1], vec![1]);
assert_eq!(t.del(&*vec![1]), Some(vec![1]));
assert_eq!(t.del(&*vec![1]), None);
Source

pub fn scan(&self, key: &[u8]) -> TreeIter<'_>

Iterate over tuples of keys and values, starting at the provided key.

§Examples
use rsdb::Config;
let t = Config::default().tree();
t.set(vec![1], vec![10]);
t.set(vec![2], vec![20]);
t.set(vec![3], vec![30]);
let mut iter = t.scan(&*vec![2]);
assert_eq!(iter.next(), Some((vec![2], vec![20])));
assert_eq!(iter.next(), Some((vec![3], vec![30])));
assert_eq!(iter.next(), None);
Source

pub fn iter(&self) -> TreeIter<'_>

Iterate over the tuples of keys and values in this tree.

§Examples
use rsdb::Config;
let t = Config::default().tree();
t.set(vec![1], vec![10]);
t.set(vec![2], vec![20]);
t.set(vec![3], vec![30]);
let mut iter = t.iter();
assert_eq!(iter.next(), Some((vec![1], vec![10])));
assert_eq!(iter.next(), Some((vec![2], vec![20])));
assert_eq!(iter.next(), Some((vec![3], vec![30])));
assert_eq!(iter.next(), None);

Trait Implementations§

Source§

impl Debug for Tree

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> IntoIterator for &'a Tree

Source§

type Item = (Vec<u8>, Vec<u8>)

The type of the elements being iterated over.
Source§

type IntoIter = TreeIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> TreeIter<'a>

Creates an iterator from a value. Read more
Source§

impl Send for Tree

Source§

impl Sync for Tree

Auto Trait Implementations§

§

impl !Freeze for Tree

§

impl !RefUnwindSafe for Tree

§

impl Unpin for Tree

§

impl !UnwindSafe for Tree

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.