pub struct Graph {
pub nodes: BTreeMap<NodeId, GraphNode>,
pub edges: BTreeSet<GraphEdge>,
/* private fields */
}Expand description
Experience/thought graph G — 𝔸3. Only Match mutates it (FORMAL_SPEC §6.3).
Fields§
§nodes: BTreeMap<NodeId, GraphNode>Nodes by id. Ordered for reproducible iteration.
Direct mutation bypasses the GraphOp journal: use it in tests (to
build corrupt states that Inv3 must reject) and in deserialization,
never in the engine.
edges: BTreeSet<GraphEdge>Typed edges. Ordered for reproducible iteration; a set, so AddEdge is
idempotent by construction (ℙ3).
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
|V|.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
|E|.
Sourcepub fn next_id(&self) -> NodeId
pub fn next_id(&self) -> NodeId
The next id this graph will hand out. Policies allocate from here so ids stay monotone no matter who proposes the op.
Sourcepub fn ok(&self, latent_dim: usize) -> bool
pub fn ok(&self, latent_dim: usize) -> bool
GraphOK(G) — Inv3.
Every edge connects existing nodes, and every node carries a finite
latent_dim-dimensional embedding. Also checks the map key against the
node’s own id, which direct field access could desync.
Sourcepub fn is_acyclic(&self) -> bool
pub fn is_acyclic(&self) -> bool
Whether the directed structure is acyclic (Inv7 candidate gate).
Kahn’s algorithm: a DAG admits a topological order covering every node.
Sourcepub fn apply(
&mut self,
op: &GraphOp,
latent_dim: usize,
) -> Result<UndoOp, GraphOpError>
pub fn apply( &mut self, op: &GraphOp, latent_dim: usize, ) -> Result<UndoOp, GraphOpError>
Apply one atomic op, returning the entry that reverses it.
Integrity is checked before any mutation, so an Err leaves G
byte-identical and the returned journal stays a faithful pre-image (𝕃6).
Sourcepub fn same_content(&self, other: &Graph) -> bool
pub fn same_content(&self, other: &Graph) -> bool
Whether two graphs hold the same (V, E, ℳ), ignoring the id counter.
This is the equality that 𝕃6 transactionality is about: Self::undo
restores the graph, while Self::next_id stays monotone on purpose
(see Self::undo), so == — which compares the counter too — is the
wrong predicate for “the rollback worked”.
Sourcepub fn undo(&mut self, entry: &UndoOp)
pub fn undo(&mut self, entry: &UndoOp)
Reverse one journal entry.
Restores (V, E, ℳ) exactly. It deliberately does not rewind
Self::next_id: recycling the id of a rolled-back node would let a
stale auxiliary entry (a vector-index tombstone that a revert missed)
alias a genuinely new node. Monotone allocation makes that class of bug
unrepresentable, and an unused id costs nothing.