solverforge-scoring 0.26.1

Incremental constraint scoring for SolverForge
Documentation
//! Diagnostics describing how many named terminals share one relational node.
//!
//! The canonical grouping migration routes every grouped, cross-grouped,
//! projected, and complemented stream through the single `GroupNode` operator.
//! These diagnostics report how many `#[solverforge_constraints]` terminals were
//! authored over that one shared accumulator, which is the compiler-owned
//! sharing contract made visible to operators.

/// Identity of the shared node within the compiled constraint program.
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct SharedNodeId(pub usize);

/// The relational family of the shared node, named for diagnostics only.
#[derive(Debug, PartialEq, Eq, Hash)]
pub enum SharedNodeOperation {
    /// Grouped rows over a unary stream.
    Grouped,
    /// Projected rows grouped into a shared accumulator.
    ProjectedGrouped,
    /// Cross-bi joined rows grouped into a shared accumulator.
    CrossGrouped,
    /// Cross-bi joined rows grouped, then complemented with default rows.
    CrossComplementedGrouped,
    /// Projected rows grouped, then complemented with default rows.
    ProjectedComplementedGrouped,
}

/// A single shared node's diagnostics: its shared consumers and root
/// notification bookkeeping while the terminal was incrementally live.
#[derive(Debug, PartialEq, Eq)]
pub struct SharedNodeDiagnostics {
    /// Identity of the shared node.
    pub id: SharedNodeId,
    /// Compiler fingerprint of the node's structure.
    pub fingerprint: String,
    /// Relational family of the node.
    pub operation: SharedNodeOperation,
    /// Names of the terminals authored over this node.
    pub terminal_consumers: Vec<String>,
    /// Number of entity notifications that changed at least one of the node's
    /// rows.
    pub update_count: usize,
    /// Number of group keys whose collector result a notification changed,
    /// summed over notifications. One notification can change several keys,
    /// or none while still changing rows (a complemented or joined node's
    /// non-grouped side).
    pub changed_key_count: usize,
}

impl SharedNodeDiagnostics {
    /// Creates diagnostics from their parts.
    pub fn new(
        id: SharedNodeId,
        fingerprint: impl Into<String>,
        operation: SharedNodeOperation,
        terminal_consumers: Vec<String>,
        update_count: usize,
        changed_key_count: usize,
    ) -> Self {
        Self {
            id,
            fingerprint: fingerprint.into(),
            operation,
            terminal_consumers,
            update_count,
            changed_key_count,
        }
    }
}