Memtable

Struct Memtable 

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

Memtable - an in-memory sorted write buffer

Provides O(log n) insert, lookup, and delete operations. When the memtable reaches a size threshold, it should be flushed to disk as an SSTable.

Implementations§

Source§

impl Memtable

Source

pub fn new() -> Memtable

Creates a new empty Memtable

Source

pub fn with_sequence(sequence: u64) -> Memtable

Creates a new Memtable with a starting sequence number

Source

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

Inserts or updates a key-value pair

Source

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

Retrieves a value by key

Returns:

  • Some(Some(value)) if the key exists with a value
  • Some(None) if the key was deleted (tombstone)
  • None if the key is not in the memtable
Source

pub fn delete(&mut self, key: Vec<u8>)

Marks a key as deleted with a tombstone

Source

pub fn size_bytes(&self) -> u64

Returns the approximate size of the memtable in bytes

Source

pub fn len(&self) -> usize

Returns the number of entries in the memtable

Source

pub fn is_empty(&self) -> bool

Returns true if the memtable is empty

Source

pub fn sequence(&self) -> u64

Returns the current sequence number

Source

pub fn iter(&self) -> impl Iterator<Item = (&Vec<u8>, &MemtableEntry)>

Returns an iterator over all entries in sorted order

Source

pub fn range<R>( &self, range: R, ) -> impl Iterator<Item = (&Vec<u8>, &MemtableEntry)>
where R: RangeBounds<Vec<u8>>,

Returns an iterator over a range of keys

Source

pub fn clear(&mut self)

Clears the memtable

Source

pub fn into_iter(self) -> impl Iterator<Item = (Vec<u8>, MemtableEntry)>

Consumes the memtable and returns all entries sorted by key

Trait Implementations§

Source§

impl Debug for Memtable

Source§

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

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

impl Default for Memtable

Source§

fn default() -> Memtable

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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