pub struct Entry<'a, K, V>{ /* private fields */ }Available on crate feature
bounded only.Expand description
An entry in the Memtable.
Implementations§
Source§impl<K, V> Entry<'_, K, V>
impl<K, V> Entry<'_, K, V>
Sourcepub fn next(&self) -> Option<Self>
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);Sourcepub fn prev(&self) -> Option<Self>
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§
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>
impl<'a, K, V> UnwindSafe for Entry<'a, K, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
Source§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
Source§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> IntoAmong for T
impl<T> IntoAmong for T
Source§fn into_among_with<F>(self, into_left: F) -> Among<Self, Self, Self>
fn into_among_with<F>(self, into_left: F) -> Among<Self, Self, Self>
Converts
self into a Left variant of Among<Self, Self>
if into_left(&self) returns Some(true). Read moreSource§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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