pub struct GraphData {
pub graph: DiGraph<Node, Edge>,
pub node_indices: HashMap<String, NodeIndex>,
pub nodes: HashMap<String, Node>,
pub edges: Vec<Edge>,
}Expand description
Core graph data structure.
Wraps a petgraph DiGraph with lookup tables for efficient access.
Supports runtime mutation (add/remove nodes and edges) without full rebuild.
Fields§
§graph: DiGraph<Node, Edge>The underlying directed graph.
node_indices: HashMap<String, NodeIndex>Lookup table: node ID → petgraph NodeIndex.
nodes: HashMap<String, Node>Lookup table: node ID → Node data.
edges: Vec<Edge>All edges as a flat list (for serialization).
Implementations§
Source§impl GraphData
impl GraphData
Sourcepub fn prerequisites(&self, node_id: &str) -> Result<Vec<Node>>
pub fn prerequisites(&self, node_id: &str) -> Result<Vec<Node>>
Get direct prerequisites of a node (incoming Prerequisite edges).
Sourcepub fn dependents(&self, node_id: &str) -> Result<Vec<Node>>
pub fn dependents(&self, node_id: &str) -> Result<Vec<Node>>
Get nodes that depend on this node (outgoing Prerequisite edges pointing here).
Get nodes related by a specific relationship type (outgoing direction).
Source§impl GraphData
impl GraphData
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of edges.
Sourcepub fn get_index(&self, id: &str) -> Option<NodeIndex>
pub fn get_index(&self, id: &str) -> Option<NodeIndex>
Gets the petgraph NodeIndex for a node ID.
Sourcepub fn contains_node(&self, id: &str) -> bool
pub fn contains_node(&self, id: &str) -> bool
Checks if a node exists.
Sourcepub fn iter_nodes(&self) -> impl Iterator<Item = &Node>
pub fn iter_nodes(&self) -> impl Iterator<Item = &Node>
Returns an iterator over all nodes.
Sourcepub fn iter_edges(&self) -> impl Iterator<Item = &Edge>
pub fn iter_edges(&self) -> impl Iterator<Item = &Edge>
Returns an iterator over all edges.
Sourcepub fn add_node(&mut self, node: Node) -> NodeIndex
pub fn add_node(&mut self, node: Node) -> NodeIndex
Add a node to the graph at runtime.
Returns the NodeIndex for the newly added node.
If a node with the same ID already exists, returns its existing index.
Sourcepub fn add_edge(&mut self, edge: Edge) -> Result<()>
pub fn add_edge(&mut self, edge: Edge) -> Result<()>
Add an edge between two nodes identified by ID.
Both nodes must already exist in the graph.
Returns Ok(()) on success, or an error if a node is missing.
Sourcepub fn remove_node(&mut self, id: &str) -> Option<Node>
pub fn remove_node(&mut self, id: &str) -> Option<Node>
Remove a node and all its connected edges.
Returns the removed node, or None if the node didn’t exist.