Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'release/scripts/startup/nodes/utils/graph.py')
-rw-r--r--release/scripts/startup/nodes/utils/graph.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/release/scripts/startup/nodes/utils/graph.py b/release/scripts/startup/nodes/utils/graph.py
new file mode 100644
index 00000000000..0a7ebcb6e1b
--- /dev/null
+++ b/release/scripts/startup/nodes/utils/graph.py
@@ -0,0 +1,19 @@
+def iter_connected_components(nodes: set, links: dict):
+ nodes = set(nodes)
+ while len(nodes) > 0:
+ start_node = next(iter(nodes))
+ component = depth_first_search(start_node, links)
+ yield component
+ nodes -= component
+
+def depth_first_search(start_node, links):
+ result = set()
+ found = set()
+ found.add(start_node)
+ while len(found) > 0:
+ node = found.pop()
+ result.add(node)
+ for linked_node in links[node]:
+ if linked_node not in result:
+ found.add(linked_node)
+ return result