Skip to main content

InMemoryStore

Struct InMemoryStore 

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

In-memory state store using BTreeMap for sorted key access.

This state store is suitable for state that fits in memory. It uses BTreeMap which provides O(log n + k) prefix and range scans, making it efficient for join state and windowed aggregation lookups.

§Performance Characteristics

  • Get: O(log n), < 500ns typical
  • Put: O(log n), may allocate
  • Delete: O(log n)
  • Prefix scan: O(log n + k) where k is matching entries
  • Range scan: O(log n + k) where k is matching entries

§Memory Usage

Keys and values are stored as owned Vec<u8> and Bytes respectively. Use size_bytes() to monitor memory usage.

Implementations§

Source§

impl InMemoryStore

Source

pub fn new() -> Self

Creates a new empty in-memory store.

Source

pub fn with_capacity(_capacity: usize) -> Self

Creates a new in-memory store.

The capacity hint is accepted for API compatibility but has no effect — BTreeMap does not support pre-allocation.

Source

pub fn capacity(&self) -> usize

Returns the number of entries in the store.

BTreeMap does not expose a capacity concept, so this returns the current entry count.

Source

pub fn shrink_to_fit(&mut self)

No-op for API compatibility.

BTreeMap manages its own memory and does not support explicit shrinking.

Trait Implementations§

Source§

impl Default for InMemoryStore

Source§

fn default() -> Self

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

impl StateStore for InMemoryStore

Source§

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

Get a value by key. Read more
Source§

fn put(&mut self, key: &[u8], value: &[u8]) -> Result<(), StateError>

Store a key-value pair. Read more
Source§

fn delete(&mut self, key: &[u8]) -> Result<(), StateError>

Delete a key. Read more
Source§

fn prefix_scan<'a>( &'a self, prefix: &'a [u8], ) -> Box<dyn Iterator<Item = (Bytes, Bytes)> + 'a>

Scan all keys with a given prefix. Read more
Source§

fn range_scan<'a>( &'a self, range: Range<&'a [u8]>, ) -> Box<dyn Iterator<Item = (Bytes, Bytes)> + 'a>

Range scan between two keys (exclusive end). Read more
Source§

fn contains(&self, key: &[u8]) -> bool

Check if a key exists. Read more
Source§

fn size_bytes(&self) -> usize

Get approximate size in bytes. Read more
Source§

fn len(&self) -> usize

Get the number of entries in the store.
Source§

fn snapshot(&self) -> StateSnapshot

Create a snapshot for checkpointing. Read more
Source§

fn restore(&mut self, snapshot: StateSnapshot)

Restore from a snapshot. Read more
Source§

fn clear(&mut self)

Clear all entries.
Source§

fn is_empty(&self) -> bool

Check if the store is empty.
Source§

fn flush(&mut self) -> Result<(), StateError>

Flush any pending writes to durable storage. Read more
Source§

fn get_or_insert( &mut self, key: &[u8], default: &[u8], ) -> Result<Bytes, StateError>

Get a value or insert a default. 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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> StateStoreExt for T
where T: StateStore + ?Sized,

Source§

fn get_typed<T>(&self, key: &[u8]) -> Result<Option<T>, StateError>

Get a value and deserialize it using rkyv. Read more
Source§

fn put_typed<T>(&mut self, key: &[u8], value: &T) -> Result<(), StateError>

Serialize and store a value using rkyv. Read more
Source§

fn update<F>(&mut self, key: &[u8], f: F) -> Result<(), StateError>
where F: FnOnce(Option<Bytes>) -> Option<Vec<u8>>,

Update a value in place using a closure. 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,