pub struct MemStore { /* private fields */ }Expand description
A simple in-memory implementation of Store.
Supports semi-naive evaluation by tracking “stable” and “delta” facts.
Compound values are stored inline: each Value::Compound is flattened into
a CompoundStart(n) marker followed by its elements. This avoids nested
heap allocations in stored tuples and enables future per-field indexing.
Implementations§
Source§impl MemStore
impl MemStore
pub fn new() -> Self
Sourcepub fn create_relation(&mut self, relation: &str)
pub fn create_relation(&mut self, relation: &str)
Registers a relation (creating it if absent) to allow scanning it.
Sourcepub fn add_fact(&mut self, relation: &str, args: Vec<Value>)
pub fn add_fact(&mut self, relation: &str, args: Vec<Value>)
Add a fact manually (for testing/setup). Auto-creates relation in stable.
pub fn get_facts(&self, relation: &str) -> Vec<Vec<Value>>
Sourcepub fn coalesce_temporal(&mut self, relation: &str)
pub fn coalesce_temporal(&mut self, relation: &str)
Coalesce temporal intervals for a relation. Groups facts by their non-temporal columns (all except the last 2), sorts intervals by start time, and merges overlapping/adjacent intervals. This prevents interval explosion in recursive temporal rules.
Trait Implementations§
Source§impl Store for MemStore
impl Store for MemStore
Source§fn scan(
&self,
relation: &str,
) -> Result<Box<dyn Iterator<Item = Vec<Value>> + '_>>
fn scan( &self, relation: &str, ) -> Result<Box<dyn Iterator<Item = Vec<Value>> + '_>>
Returns an iterator over all tuples in the relation.
Returns an error if the relation does not exist.
Source§fn scan_delta(
&self,
relation: &str,
) -> Result<Box<dyn Iterator<Item = Vec<Value>> + '_>>
fn scan_delta( &self, relation: &str, ) -> Result<Box<dyn Iterator<Item = Vec<Value>> + '_>>
Returns an iterator over only the new tuples added in the last iteration.
Source§fn scan_next_delta(
&self,
relation: &str,
) -> Result<Box<dyn Iterator<Item = Vec<Value>> + '_>>
fn scan_next_delta( &self, relation: &str, ) -> Result<Box<dyn Iterator<Item = Vec<Value>> + '_>>
Returns an iterator over tuples being collected for the next iteration.
Source§fn scan_index(
&self,
relation: &str,
col_idx: usize,
key: &Value,
) -> Result<Box<dyn Iterator<Item = Vec<Value>> + '_>>
fn scan_index( &self, relation: &str, col_idx: usize, key: &Value, ) -> Result<Box<dyn Iterator<Item = Vec<Value>> + '_>>
Returns an iterator over tuples in the relation matching a key in a column.
Source§fn scan_delta_index(
&self,
relation: &str,
col_idx: usize,
key: &Value,
) -> Result<Box<dyn Iterator<Item = Vec<Value>> + '_>>
fn scan_delta_index( &self, relation: &str, col_idx: usize, key: &Value, ) -> Result<Box<dyn Iterator<Item = Vec<Value>> + '_>>
Returns an iterator over delta tuples matching a key in a column.
Source§fn insert(&mut self, relation: &str, tuple: Vec<Value>) -> Result<bool>
fn insert(&mut self, relation: &str, tuple: Vec<Value>) -> Result<bool>
Inserts a tuple into the relation (specifically into the delta/new set).
Returns true if it was new.
Source§fn merge_deltas(&mut self)
fn merge_deltas(&mut self)
Merges current deltas into the stable set of facts.
Source§fn create_relation(&mut self, relation: &str)
fn create_relation(&mut self, relation: &str)
Ensures a relation exists in the store.
Source§fn retract(&mut self, relation: &str, tuple: &[Value]) -> Result<bool>
fn retract(&mut self, relation: &str, tuple: &[Value]) -> Result<bool>
Removes a specific tuple from the relation’s stable set.
Returns true if the tuple was found and removed.
Source§fn clear(&mut self, relation: &str)
fn clear(&mut self, relation: &str)
Removes all tuples from a relation (stable, delta, and next_delta).
Source§fn relation_names(&self) -> Vec<String>
fn relation_names(&self) -> Vec<String>
Returns the names of all relations in the store.
Source§fn coalesce_temporal(&mut self, relation: &str)
fn coalesce_temporal(&mut self, relation: &str)
Coalesce temporal intervals for a relation.
Groups facts by their non-temporal columns (all except the last 2),
sorts intervals by start time, and merges overlapping/adjacent intervals.
Default implementation is a no-op.
Auto Trait Implementations§
impl Freeze for MemStore
impl RefUnwindSafe for MemStore
impl Send for MemStore
impl Sync for MemStore
impl Unpin for MemStore
impl UnsafeUnpin for MemStore
impl UnwindSafe for MemStore
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