Skip to content

Commit

Permalink
optimize topographical sort
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitri-yatsenko committed Sep 16, 2024
1 parent b5e7cf9 commit 224785e
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions datajoint/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,15 @@ def topo_sort(graph):
placed = set()
while pos > 1:
part = sorted_nodes[pos]
if not (master := extract_master) or part in placed:
if (master := extract_master(part)) not in graph or part in placed:
pos -= 1
else:
placed.add(part)
try:
j = sorted_nodes.index(master)
except ValueError:
# master not found
pass
else:
if pos > j + 1:
# move the part to its master
del sorted_nodes[pos]
sorted_nodes.insert(j + 1, part)
j = sorted_nodes.index(master)
if pos > j + 1:
# move the part to its master
del sorted_nodes[pos]
sorted_nodes.insert(j + 1, part)

return sorted_nodes

Expand Down

0 comments on commit 224785e

Please sign in to comment.