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
impl InMemoryStore
Sourcepub fn with_capacity(_capacity: usize) -> Self
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.
Sourcepub fn capacity(&self) -> usize
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.
Sourcepub fn shrink_to_fit(&mut self)
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
impl Default for InMemoryStore
Source§impl StateStore for InMemoryStore
impl StateStore for InMemoryStore
Source§fn put(&mut self, key: &[u8], value: &[u8]) -> Result<(), StateError>
fn put(&mut self, key: &[u8], value: &[u8]) -> Result<(), StateError>
Store a key-value pair. Read more
Source§fn prefix_scan<'a>(
&'a self,
prefix: &'a [u8],
) -> Box<dyn Iterator<Item = (Bytes, Bytes)> + 'a>
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>
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 size_bytes(&self) -> usize
fn size_bytes(&self) -> usize
Get approximate size in bytes. Read more
Source§fn snapshot(&self) -> StateSnapshot
fn snapshot(&self) -> StateSnapshot
Create a snapshot for checkpointing. Read more
Source§fn restore(&mut self, snapshot: StateSnapshot)
fn restore(&mut self, snapshot: StateSnapshot)
Restore from a snapshot. Read more
Source§fn flush(&mut self) -> Result<(), StateError>
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>
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§
impl Freeze for InMemoryStore
impl RefUnwindSafe for InMemoryStore
impl Send for InMemoryStore
impl Sync for InMemoryStore
impl Unpin for InMemoryStore
impl UnwindSafe for InMemoryStore
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
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
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
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>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.Source§impl<T> StateStoreExt for Twhere
T: StateStore + ?Sized,
impl<T> StateStoreExt for Twhere
T: StateStore + ?Sized,
Source§fn get_typed<T>(&self, key: &[u8]) -> Result<Option<T>, StateError>where
T: Archive,
T::Archived: for<'a> CheckBytes<HighValidator<'a, RkyvError>> + RkyvDeserialize<T, HighDeserializer<RkyvError>>,
fn get_typed<T>(&self, key: &[u8]) -> Result<Option<T>, StateError>where
T: Archive,
T::Archived: for<'a> CheckBytes<HighValidator<'a, RkyvError>> + RkyvDeserialize<T, HighDeserializer<RkyvError>>,
Get a value and deserialize it using rkyv. Read more