Check there are no cycles in the graph (this should never happen).
(&self)
| 631 | |
| 632 | /// Check there are no cycles in the graph (this should never happen). |
| 633 | pub fn is_acyclic(&self) -> bool { |
| 634 | let mut dependencies: HashMap<NodeId, Vec<NodeId>> = HashMap::new(); |
| 635 | for (node_id, node) in &self.nodes { |
| 636 | dependencies.insert( |
| 637 | *node_id, |
| 638 | node.inputs |
| 639 | .iter() |
| 640 | .filter_map(|input| if let NodeInput::Node { node_id, .. } = input { Some(*node_id) } else { None }) |
| 641 | .collect(), |
| 642 | ); |
| 643 | } |
| 644 | while !dependencies.is_empty() { |
| 645 | let Some((&disconnected, _)) = dependencies.iter().find(|(_, l)| l.is_empty()) else { |
| 646 | error!("Dependencies {dependencies:?}"); |
| 647 | return false; |
| 648 | }; |
| 649 | dependencies.remove(&disconnected); |
| 650 | for connections in dependencies.values_mut() { |
| 651 | connections.retain(|&id| id != disconnected); |
| 652 | } |
| 653 | } |
| 654 | true |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | // Functions for resolving scope inputs |