Update all of the references to a node ID in the graph with a new ID named `compose_node_id`.
(&mut self, outwards_edges: &HashMap<NodeId, Vec<NodeId>>, node_id: NodeId, replacement_node_id: NodeId)
| 426 | |
| 427 | /// Update all of the references to a node ID in the graph with a new ID named `compose_node_id`. |
| 428 | fn replace_node_id(&mut self, outwards_edges: &HashMap<NodeId, Vec<NodeId>>, node_id: NodeId, replacement_node_id: NodeId) { |
| 429 | // Update references in other nodes to use the new node |
| 430 | if let Some(referring_nodes) = outwards_edges.get(&node_id) { |
| 431 | for &referring_node_id in referring_nodes { |
| 432 | let (_, referring_node) = &mut self.nodes[referring_node_id.0 as usize]; |
| 433 | referring_node.map_ids(|id| if id == node_id { replacement_node_id } else { id }) |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | if self.output == node_id { |
| 438 | self.output = replacement_node_id; |
| 439 | } |
| 440 | |
| 441 | self.inputs.iter_mut().for_each(|id| { |
| 442 | if *id == node_id { |
| 443 | *id = replacement_node_id; |
| 444 | } |
| 445 | }); |
| 446 | } |
| 447 | |
| 448 | // Based on https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search |
| 449 | // This approach excludes nodes that are not connected |
no test coverage detected