Skip to main content

Graph

Struct Graph 

Source
pub struct Graph {
    pub id: GraphId,
    pub blocks: HashMap<BlockId, Block>,
    pub edges: HashMap<EdgeId, HyperEdge>,
    pub atoms: HashMap<AtomId, Atom>,
    pub port_values: HashMap<PortId, Value>,
    /* private fields */
}
Expand description

A live, mutable graph of blocks, edges, and atoms.

Graph owns all domain objects and drives the execution loop. Typical usage:

  1. Create via Graph::new.
  2. Add blocks / edges / atoms.
  3. Call set_port_value to inject inputs.
  4. Call run_pending to flush the scheduler queue.
  5. Read output values via get_port_value.

Fields§

§id: GraphId

Unique id for this graph.

§blocks: HashMap<BlockId, Block>

All blocks keyed by id.

§edges: HashMap<EdgeId, HyperEdge>

All edges keyed by id.

§atoms: HashMap<AtomId, Atom>

All atoms keyed by id.

§port_values: HashMap<PortId, Value>

Current port values.

Implementations§

Source§

impl Graph

Source

pub fn new(id: GraphId, registry: TransformRegistry) -> Self

Create an empty graph with the given id and transform registry.

Source

pub fn add_block(&mut self, block: Block)

Add a block to the graph.

Source

pub fn add_edge(&mut self, edge: HyperEdge) -> Result<(), EngineError>

Add an edge to the graph and register it with the scheduler.

Delay edges (edge.delay == true) are stored in delay_edge_ids and excluded from the topological sort, allowing them to participate in feedback cycles without triggering CycleDetected.

Source

pub fn remove_block(&mut self, id: BlockId)

Remove a block by id (no-op if not present).

Source

pub fn remove_edge(&mut self, id: EdgeId) -> Result<(), EngineError>

Remove an edge by id and rebuild the topological sort.

Source

pub fn add_atom(&mut self, atom: Atom)

Add an atom to the graph.

Source

pub fn set_port_value(&mut self, port: PortId, value: Value)

Write a port value and notify the scheduler.

Source

pub fn get_port_value(&self, port: PortId) -> Option<&Value>

Read a port value (returns None if not set).

Source

pub async fn tick(&mut self, delta: Duration) -> Result<(), EngineError>

Advance the tick-based scheduler by delta and run any newly pending edges.

Source

pub async fn fire_event(&mut self, name: &str) -> Result<(), EngineError>

Fire a named event and run any newly pending edges.

Source

pub async fn run_pending(&mut self) -> Result<(), EngineError>

Drain the scheduler queue and execute pending edges in parallel waves.

Delay buffer flush: at the start of each call the delay buffer from the previous tick is applied to port_values and its ports are notified, so their downstream normal edges are included in this tick’s execution.

Normal edges are grouped into independent waves by compute_levels and executed concurrently within each wave via try_join_all.

Delay edges run after all normal waves. Their outputs are written into the delay buffer rather than port_values, deferring the effect to the next tick.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.