Struct Entry

Source
pub struct Entry<'a, K, V>
where K: ?Sized + Type, V: ?Sized + Type,
{ /* private fields */ }
Available on crate feature bounded only.
Expand description

An entry in the Memtable.

Implementations§

Source§

impl<'a, K, V> Entry<'a, K, V>
where K: ?Sized + Type, V: ?Sized + Type,

Source

pub fn key(&self) -> &K::Ref<'a>

Returns the key of the entry.

Source

pub fn value(&self) -> &V::Ref<'a>

Returns the value of the entry.

Source

pub const fn version(&self) -> u64

Returns the version of the entry.

Source§

impl<K, V> Entry<'_, K, V>
where K: ?Sized + Type + 'static, for<'a> K::Ref<'a>: KeyRef<'a, K>, V: ?Sized + Type + 'static,

Source

pub fn next(&self) -> Option<Self>

Returns the next entry in the Memtable.

use memorable::bounded::{generic::Memtable, Options};
use core::ops::Bound;

let memtable: Memtable<usize, str> = Options::new().alloc().unwrap();

memtable.insert(0, &1, "one").unwrap();
memtable.insert(0, &2, "two").unwrap();
memtable.insert(0, &3, "three").unwrap();
memtable.insert(0, &4, "four").unwrap();

memtable.remove_range::<usize, _>(1, (Bound::Excluded(&1), Bound::Unbounded)).unwrap();

memtable.update_range::<usize, _>(2, (Bound::Unbounded, Bound::Included(&2)), "updated").unwrap();

// At view 0, the memtable contains 4 entries.
let mut num = 0;
let mut ent = memtable.first(0);
while let Some(entry) = ent {
  assert_eq!(entry.key(), &(num + 1));
  num += 1;
  ent = entry.next();
}
assert_eq!(num, 4);

// At view 1, the memtable contains 1 entry because of remove_range..
let mut num = 0;
let mut ent = memtable.first(1);
while let Some(entry) = ent {
  assert_eq!(entry.key(), &(num + 1));
  assert_eq!(*entry.value(), "one");
  ent = entry.next();
  num += 1;
}
assert_eq!(num, 1);

// At view 2, the memtable contains 1 entry because of update_range, and the value is updated because of the update_range.
let mut num = 0;
let mut ent = memtable.first(2);
while let Some(entry) = ent {
  assert_eq!(entry.key(), &(num + 1));
  assert_eq!(*entry.value(), "updated");
  ent = entry.next();
  num += 1;
}
assert_eq!(num, 1);
Source

pub fn prev(&self) -> Option<Self>

Returns the previous entry in the Memtable.

use memorable::bounded::{generic::Memtable, Options};
use core::ops::Bound;

let memtable: Memtable<usize, str> = Options::new().alloc().unwrap();

memtable.insert(0, &1, "one").unwrap();
memtable.insert(0, &2, "two").unwrap();
memtable.insert(0, &3, "three").unwrap();
memtable.insert(0, &4, "four").unwrap();

memtable.remove_range::<usize, _>(1, (Bound::Unbounded, Bound::Included(&3))).unwrap();

memtable.update_range::<usize, _>(2, (Bound::Included(&2), Bound::Unbounded), "updated").unwrap();

// At view 0, the memtable contains 4 entries.
let mut num = 4;
let mut ent = memtable.last(0);
while let Some(entry) = ent {
  assert_eq!(entry.key(), &num);
  ent = entry.prev();
  num -= 1;
}
assert_eq!(num, 0);

// At view 1, the memtable only contains 4 because of remove_range.
let mut num = 0;
let mut ent = memtable.last(1);
while let Some(entry) = ent {
  assert_eq!(entry.key(), &4);
  assert_eq!(*entry.value(), "four");
  ent = entry.prev();
  num += 1;
}
assert_eq!(num, 1);

// At view 2, the memtable only contains 4 because of update_range, and the value is updated because of the update_range.
let mut num = 0;
let mut ent = memtable.last(2);
while let Some(entry) = ent {
  assert_eq!(entry.key(), &4);
  assert_eq!(*entry.value(), "updated");
  ent = entry.prev();
  num += 1;
}
assert_eq!(num, 1);

Trait Implementations§

Source§

impl<K, V> Clone for Entry<'_, K, V>
where K: ?Sized + Type, V: ?Sized + Type,

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

impl<K, V> Debug for Entry<'_, K, V>
where K: Debug + Type + ?Sized, V: Debug + Type + ?Sized,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, K, V> !Freeze for Entry<'a, K, V>

§

impl<'a, K, V> !RefUnwindSafe for Entry<'a, K, V>

§

impl<'a, K, V> !Send for Entry<'a, K, V>

§

impl<'a, K, V> !Sync for Entry<'a, K, V>

§

impl<'a, K, V> Unpin for Entry<'a, K, V>
where <V as Type>::Ref<'a>: Unpin, <K as Type>::Ref<'a>: Unpin, K: ?Sized, V: ?Sized,

§

impl<'a, K, V> UnwindSafe for Entry<'a, K, V>
where <V as Type>::Ref<'a>: UnwindSafe, <K as Type>::Ref<'a>: UnwindSafe, K: ?Sized, V: ?Sized,

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<K, Q> Comparable<Q> for K
where K: Borrow<Q> + ?Sized, Q: Ord + ?Sized,

Source§

fn compare(&self, key: &Q) -> Ordering

Compare self to key and return their ordering.
Source§

impl<K, Q> Equivalent<Q> for K
where K: Borrow<Q> + ?Sized, Q: Eq + ?Sized,

Source§

fn equivalent(&self, key: &Q) -> bool

Compare self to key and return true if they are equal.
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> IntoAmong for T

Source§

fn into_among(self, into_left: Option<bool>) -> Among<Self, Self, Self>

Converts self into a Left variant of Among<Self, Self> if into_left is Some(true). Read more
Source§

fn into_among_with<F>(self, into_left: F) -> Among<Self, Self, Self>
where F: FnOnce(&Self) -> Option<bool>,

Converts self into a Left variant of Among<Self, Self> if into_left(&self) returns Some(true). Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V