Created
November 9, 2021 08:36
-
-
Save thomaspoignant/504149bd09d1aae7790e3866459cef54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sort the stages | |
out_degree_map = {v: d for v, d in g.out_degree() if d > 0} | |
zero_out_degree = [v for v, d in g.out_degree() if d == 0] | |
while zero_out_degree: | |
yield zero_out_degree | |
new_zero_out_degree = [] | |
for v in zero_out_degree: | |
for child, _ in g.in_edges(v): | |
out_degree_map[child] -= 1 | |
if not out_degree_map[child]: | |
new_zero_out_degree.append(child) | |
zero_out_degree = new_zero_out_degree |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment