Skip to content

Commit 224785e

Browse files
optimize topographical sort
1 parent b5e7cf9 commit 224785e

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

datajoint/dependencies.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,15 @@ def topo_sort(graph):
5151
placed = set()
5252
while pos > 1:
5353
part = sorted_nodes[pos]
54-
if not (master := extract_master) or part in placed:
54+
if (master := extract_master(part)) not in graph or part in placed:
5555
pos -= 1
5656
else:
5757
placed.add(part)
58-
try:
59-
j = sorted_nodes.index(master)
60-
except ValueError:
61-
# master not found
62-
pass
63-
else:
64-
if pos > j + 1:
65-
# move the part to its master
66-
del sorted_nodes[pos]
67-
sorted_nodes.insert(j + 1, part)
58+
j = sorted_nodes.index(master)
59+
if pos > j + 1:
60+
# move the part to its master
61+
del sorted_nodes[pos]
62+
sorted_nodes.insert(j + 1, part)
6863

6964
return sorted_nodes
7065

0 commit comments

Comments
 (0)