A simple DFS helper routine
(v_i, path=None)
| 231 | visited = set() |
| 232 | |
| 233 | def dfs(v_i, path=None): |
| 234 | """A simple DFS helper routine""" |
| 235 | path = set([v_i]) if path is None else path |
| 236 | for nbr_i in self.get_neighbors(v_i): |
| 237 | if nbr_i in path: |
| 238 | return True # cycle detected! |
| 239 | elif nbr_i not in visited: |
| 240 | visited.add(nbr_i) |
| 241 | path.add(nbr_i) |
| 242 | is_cyclic = dfs(nbr_i, path) |
| 243 | if is_cyclic: |
| 244 | return True |
| 245 | |
| 246 | # insert to the beginning of the ordering |
| 247 | ordering.insert(0, v_i) |
| 248 | path -= set([v_i]) |
| 249 | return False |
| 250 | |
| 251 | for s_i in self.indices: |
| 252 | if s_i not in visited: |
nothing calls this directly
no test coverage detected