MCPcopy Index your code
hub / github.com/DeepLabCut/DeepLabCut / find_cycles

Function find_cycles

tools/find_import_cycles.py:71–105  ·  view source on GitHub ↗
(edges: dict[str, set[str]])

Source from the content-addressed store, hash-verified

69
70
71def find_cycles(edges: dict[str, set[str]]) -> list[list[str]]:
72 visited = set()
73 stack = []
74 on_stack = set()
75 cycles = []
76
77 def dfs(node: str):
78 visited.add(node)
79 stack.append(node)
80 on_stack.add(node)
81
82 for neighbor in edges.get(node, ()):
83 if neighbor not in visited:
84 dfs(neighbor)
85 elif neighbor in on_stack:
86 idx = stack.index(neighbor)
87 cycle = stack[idx:] + [neighbor]
88 cycles.append(cycle)
89
90 stack.pop()
91 on_stack.remove(node)
92
93 for node in edges:
94 if node not in visited:
95 dfs(node)
96
97 # Deduplicate roughly
98 seen = set()
99 unique = []
100 for cyc in cycles:
101 key = tuple(cyc)
102 if key not in seen:
103 seen.add(key)
104 unique.append(cyc)
105 return unique
106
107
108def main():

Callers 1

mainFunction · 0.85

Calls 2

dfsFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected