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:
- Create via
Graph::new. - Add blocks / edges / atoms.
- Call
set_port_valueto inject inputs. - Call
run_pendingto flush the scheduler queue. - Read output values via
get_port_value.
Fields§
§id: GraphIdUnique 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
impl Graph
Sourcepub fn new(id: GraphId, registry: TransformRegistry) -> Self
pub fn new(id: GraphId, registry: TransformRegistry) -> Self
Create an empty graph with the given id and transform registry.
Sourcepub fn add_edge(&mut self, edge: HyperEdge) -> Result<(), EngineError>
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.
Sourcepub fn remove_block(&mut self, id: BlockId)
pub fn remove_block(&mut self, id: BlockId)
Remove a block by id (no-op if not present).
Sourcepub fn remove_edge(&mut self, id: EdgeId) -> Result<(), EngineError>
pub fn remove_edge(&mut self, id: EdgeId) -> Result<(), EngineError>
Remove an edge by id and rebuild the topological sort.
Sourcepub fn set_port_value(&mut self, port: PortId, value: Value)
pub fn set_port_value(&mut self, port: PortId, value: Value)
Write a port value and notify the scheduler.
Sourcepub fn get_port_value(&self, port: PortId) -> Option<&Value>
pub fn get_port_value(&self, port: PortId) -> Option<&Value>
Read a port value (returns None if not set).
Sourcepub async fn tick(&mut self, delta: Duration) -> Result<(), EngineError>
pub async fn tick(&mut self, delta: Duration) -> Result<(), EngineError>
Advance the tick-based scheduler by delta and run any newly pending edges.
Sourcepub async fn fire_event(&mut self, name: &str) -> Result<(), EngineError>
pub async fn fire_event(&mut self, name: &str) -> Result<(), EngineError>
Fire a named event and run any newly pending edges.
Sourcepub async fn run_pending(&mut self) -> Result<(), EngineError>
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.