Skip to main content

Session

Struct Session 

Source
pub struct Session<S: Score> {
    pub nodes: NodeArena<S>,
    pub tuples: TupleArena,
    /* private fields */
}
Expand description

High-performance session with minimal overhead in hot paths

Fields§

§nodes: NodeArena<S>§tuples: TupleArena

Implementations§

Source§

impl<S: Score + 'static> Session<S>

Source

pub fn insert<T: GreynetFact + 'static>(&mut self, fact: T) -> Result<()>

CRITICAL PERFORMANCE FIX: Removed statistics tracking from hot path

Source

pub fn insert_batch<T: GreynetFact + 'static>( &mut self, facts: impl IntoIterator<Item = T>, ) -> Result<()>

Inserts a collection of facts into the session.

Source

pub fn insert_bulk<T: GreynetFact + 'static>( &mut self, facts: Vec<T>, ) -> Result<()>

Bulk insert with performance optimization

Source

pub fn retract<T: GreynetFact>(&mut self, fact: &T) -> Result<()>

Retracts a fact from the session, scheduling it for removal.

Source

pub fn retract_batch<'a, T: GreynetFact + 'a>( &mut self, facts: impl IntoIterator<Item = &'a T>, ) -> Result<()>

Retracts a collection of facts from the session.

Source

pub fn clear(&mut self) -> Result<()>

Removes all facts from the session.

Source

pub fn flush(&mut self) -> Result<()>

Processes all pending insertions and retractions until the network is stable.

Source

pub fn flush_with_optimizations(&mut self) -> Result<()>

Flush with additional optimizations for large datasets

Source

pub fn get_score(&mut self) -> Result<S>

Calculates and returns the total score for the current state of the network.

Source

pub fn update_constraint_weight( &mut self, constraint_id_str: &str, new_weight: f64, ) -> Result<()>

Updates a constraint’s weight and triggers a score recalculation.

Source

pub fn update_constraint_weights( &mut self, weight_updates: HashMap<String, f64>, ) -> Result<()>

Bulk update multiple constraint weights

Source

pub fn get_constraint_matches( &mut self, ) -> Result<HashMap<String, Vec<AnyTuple>>>

Retrieves all tuples that are currently violating any constraints.

Source

pub fn get_constraint_matches_with_stats( &mut self, ) -> Result<HashMap<String, (Vec<AnyTuple>, usize, S)>>

Get constraint matches with detailed statistics

Source

pub fn get_fact_constraint_matches( &mut self, fact_id: i64, ) -> Result<Vec<FactConstraintMatch<S>>>

Retrieves all constraint violations that involve a specific fact.

Source

pub fn get_fact_constraint_matches_by_fact<T: GreynetFact>( &mut self, fact: &T, ) -> Result<Vec<FactConstraintMatch<S>>>

Retrieves constraint matches for a specific fact by the fact object itself.

Source

pub fn get_all_fact_constraint_matches( &mut self, ) -> Result<FactConstraintReport<S>>

Generates a comprehensive report of all constraint violations, grouped by fact.

Source

pub fn get_statistics(&self) -> SessionStatistics

Gets comprehensive statistics about the session’s state. PERFORMANCE FIX: Cached and lazy computation

Source

pub fn get_detailed_statistics(&self) -> SessionStatistics

PERFORMANCE FIX: Expensive statistics computed only on explicit request

Source

pub fn validate_consistency(&self) -> Result<()>

Source

pub fn check_resource_limits(&self) -> Result<()>

Source

pub fn bulk_transition_tuple_states( &mut self, from: TupleState, to: TupleState, ) -> Result<usize>

Source

pub fn cleanup_dying_tuples(&mut self) -> Result<usize>

Trait Implementations§

Source§

impl<S: Debug + Score> Debug for Session<S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> !Freeze for Session<S>

§

impl<S> !RefUnwindSafe for Session<S>

§

impl<S> !Send for Session<S>

§

impl<S> !Sync for Session<S>

§

impl<S> !UnwindSafe for Session<S>

§

impl<S> Unpin for Session<S>
where S: Unpin, <S as Score>::Accumulator: Unpin,

§

impl<S> UnsafeUnpin for Session<S>

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.