Skip to main content

solverforge_scoring/api/
node_sharing.rs

1//! Diagnostics describing how many named terminals share one relational node.
2//!
3//! The canonical grouping migration routes every grouped, cross-grouped,
4//! projected, and complemented stream through the single `GroupNode` operator.
5//! These diagnostics report how many `#[solverforge_constraints]` terminals were
6//! authored over that one shared accumulator, which is the compiler-owned
7//! sharing contract made visible to operators.
8
9/// Identity of the shared node within the compiled constraint program.
10#[derive(Debug, PartialEq, Eq, Hash)]
11pub struct SharedNodeId(pub usize);
12
13/// The relational family of the shared node, named for diagnostics only.
14#[derive(Debug, PartialEq, Eq, Hash)]
15pub enum SharedNodeOperation {
16    /// Grouped rows over a unary stream.
17    Grouped,
18    /// Projected rows grouped into a shared accumulator.
19    ProjectedGrouped,
20    /// Cross-bi joined rows grouped into a shared accumulator.
21    CrossGrouped,
22    /// Cross-bi joined rows grouped, then complemented with default rows.
23    CrossComplementedGrouped,
24    /// Projected rows grouped, then complemented with default rows.
25    ProjectedComplementedGrouped,
26}
27
28/// A single shared node's diagnostics: its shared consumers and root
29/// notification bookkeeping while the terminal was incrementally live.
30#[derive(Debug, PartialEq, Eq)]
31pub struct SharedNodeDiagnostics {
32    pub id: SharedNodeId,
33    pub fingerprint: String,
34    pub operation: SharedNodeOperation,
35    pub terminal_consumers: Vec<String>,
36    pub update_count: usize,
37    pub changed_key_count: usize,
38}
39
40impl SharedNodeDiagnostics {
41    pub fn new(
42        id: SharedNodeId,
43        fingerprint: impl Into<String>,
44        operation: SharedNodeOperation,
45        terminal_consumers: Vec<String>,
46        update_count: usize,
47        changed_key_count: usize,
48    ) -> Self {
49        Self {
50            id,
51            fingerprint: fingerprint.into(),
52            operation,
53            terminal_consumers,
54            update_count,
55            changed_key_count,
56        }
57    }
58}