Skip to main content

Graph

Struct Graph 

Source
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

Source

pub fn empty() -> Self

An empty graph.

Source

pub fn seed(node: GraphNode) -> Self

A graph holding a single seed node.

Source

pub fn node_count(&self) -> usize

|V|.

Source

pub fn edge_count(&self) -> usize

|E|.

Source

pub fn size(&self) -> usize

|G| = |V| + |E|.

Source

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.

Source

pub fn node(&self, id: NodeId) -> Option<&GraphNode>

A node by id.

Source

pub fn get_embedding(&self, id: NodeId) -> Option<&Vec<f64>>

A node’s embedding ℳ(v).

Source

pub fn incident(&self, id: NodeId) -> Vec<GraphEdge>

Edges incident to id in either direction.

Source

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.

Source

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.

Source

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).

Source

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”.

Source

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.

Source

pub fn apply_ops( &mut self, ops: &[GraphOp], latent_dim: usize, ) -> Result<Vec<UndoOp>, GraphOpError>

Apply a batch atomically: on the first failure every applied op is reversed and G is left byte-identical to its pre-state (𝕃6).

Source

pub fn undo_ops(&mut self, journal: &[UndoOp])

Reverse a journal, newest entry first.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Graph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Graph

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Graph

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Graph

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Graph

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl UnwindSafe for Graph

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.