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: TupleArenaImplementations§
Source§impl<S: Score + 'static> Session<S>
impl<S: Score + 'static> Session<S>
Sourcepub fn insert<T: GreynetFact + 'static>(&mut self, fact: T) -> Result<()>
pub fn insert<T: GreynetFact + 'static>(&mut self, fact: T) -> Result<()>
CRITICAL PERFORMANCE FIX: Removed statistics tracking from hot path
Sourcepub fn insert_batch<T: GreynetFact + 'static>(
&mut self,
facts: impl IntoIterator<Item = T>,
) -> Result<()>
pub fn insert_batch<T: GreynetFact + 'static>( &mut self, facts: impl IntoIterator<Item = T>, ) -> Result<()>
Inserts a collection of facts into the session.
Sourcepub fn insert_bulk<T: GreynetFact + 'static>(
&mut self,
facts: Vec<T>,
) -> Result<()>
pub fn insert_bulk<T: GreynetFact + 'static>( &mut self, facts: Vec<T>, ) -> Result<()>
Bulk insert with performance optimization
Sourcepub fn retract<T: GreynetFact>(&mut self, fact: &T) -> Result<()>
pub fn retract<T: GreynetFact>(&mut self, fact: &T) -> Result<()>
Retracts a fact from the session, scheduling it for removal.
Sourcepub fn retract_batch<'a, T: GreynetFact + 'a>(
&mut self,
facts: impl IntoIterator<Item = &'a T>,
) -> Result<()>
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.
Sourcepub fn flush(&mut self) -> Result<()>
pub fn flush(&mut self) -> Result<()>
Processes all pending insertions and retractions until the network is stable.
Sourcepub fn flush_with_optimizations(&mut self) -> Result<()>
pub fn flush_with_optimizations(&mut self) -> Result<()>
Flush with additional optimizations for large datasets
Sourcepub fn get_score(&mut self) -> Result<S>
pub fn get_score(&mut self) -> Result<S>
Calculates and returns the total score for the current state of the network.
Sourcepub fn update_constraint_weight(
&mut self,
constraint_id_str: &str,
new_weight: f64,
) -> Result<()>
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.
Sourcepub fn update_constraint_weights(
&mut self,
weight_updates: HashMap<String, f64>,
) -> Result<()>
pub fn update_constraint_weights( &mut self, weight_updates: HashMap<String, f64>, ) -> Result<()>
Bulk update multiple constraint weights
Sourcepub fn get_constraint_matches(
&mut self,
) -> Result<HashMap<String, Vec<AnyTuple>>>
pub fn get_constraint_matches( &mut self, ) -> Result<HashMap<String, Vec<AnyTuple>>>
Retrieves all tuples that are currently violating any constraints.
Sourcepub fn get_constraint_matches_with_stats(
&mut self,
) -> Result<HashMap<String, (Vec<AnyTuple>, usize, S)>>
pub fn get_constraint_matches_with_stats( &mut self, ) -> Result<HashMap<String, (Vec<AnyTuple>, usize, S)>>
Get constraint matches with detailed statistics
Sourcepub fn get_fact_constraint_matches(
&mut self,
fact_id: i64,
) -> Result<Vec<FactConstraintMatch<S>>>
pub fn get_fact_constraint_matches( &mut self, fact_id: i64, ) -> Result<Vec<FactConstraintMatch<S>>>
Retrieves all constraint violations that involve a specific fact.
Sourcepub fn get_fact_constraint_matches_by_fact<T: GreynetFact>(
&mut self,
fact: &T,
) -> Result<Vec<FactConstraintMatch<S>>>
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.
Sourcepub fn get_all_fact_constraint_matches(
&mut self,
) -> Result<FactConstraintReport<S>>
pub fn get_all_fact_constraint_matches( &mut self, ) -> Result<FactConstraintReport<S>>
Generates a comprehensive report of all constraint violations, grouped by fact.
Sourcepub fn get_statistics(&self) -> SessionStatistics
pub fn get_statistics(&self) -> SessionStatistics
Gets comprehensive statistics about the session’s state. PERFORMANCE FIX: Cached and lazy computation
Sourcepub fn get_detailed_statistics(&self) -> SessionStatistics
pub fn get_detailed_statistics(&self) -> SessionStatistics
PERFORMANCE FIX: Expensive statistics computed only on explicit request