MCPcopy Create free account
hub / github.com/GraphiteEditor/Graphite / is_acyclic

Method is_acyclic

node-graph/graph-craft/src/document.rs:633–655  ·  view source on GitHub ↗

Check there are no cycles in the graph (this should never happen).

(&self)

Source from the content-addressed store, hash-verified

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

Callers 1

set_inputMethod · 0.80

Calls 5

retainMethod · 0.80
insertMethod · 0.45
iterMethod · 0.45
is_emptyMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected