Add an edge between two nodes
(&mut self, from: NodeId, to: NodeId, edge: WorkflowEdge)
| 187 | |
| 188 | /// Add an edge between two nodes |
| 189 | pub fn add_edge(&mut self, from: NodeId, to: NodeId, edge: WorkflowEdge) -> GraphBitResult<()> { |
| 190 | let from_index = self |
| 191 | .node_map |
| 192 | .get(&from) |
| 193 | .ok_or_else(|| GraphBitError::graph(format!("Source node {from} not found")))?; |
| 194 | |
| 195 | let to_index = self |
| 196 | .node_map |
| 197 | .get(&to) |
| 198 | .ok_or_else(|| GraphBitError::graph(format!("Target node {to} not found")))?; |
| 199 | |
| 200 | self.graph.add_edge(*from_index, *to_index, edge.clone()); |
| 201 | self.edges.push((from.clone(), to.clone(), edge)); |
| 202 | self.outgoing.entry(from.clone()).or_default().push(to.clone()); |
| 203 | self.incoming.entry(to.clone()).or_default().push(from.clone()); |
| 204 | |
| 205 | // Invalidate caches since graph structure changed |
| 206 | self.invalidate_caches(); |
| 207 | |
| 208 | Ok(()) |
| 209 | } |
| 210 | |
| 211 | /// Remove a node from the graph |
| 212 | pub fn remove_node(&mut self, node_id: &NodeId) -> GraphBitResult<()> { |