Created
March 2, 2011 07:26
-
-
Save aterrel/850598 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
def _rev_top_sort (self, dag): | |
"""Simple reverse top sorter given dag | |
dag: a dictionary with node:(neighbors) | |
returns a list of nodes in reversed topological order. | |
Used to determine update sequence. | |
""" | |
ret_list = [] | |
visited = [] | |
def _visit (node, deps): | |
if node in deps: | |
raise ValueError, "Given dag has a cycle." | |
if node not in visited: | |
visited.append(node) | |
deps = deps + [node] | |
map(lambda n: _visit(n, deps), dag[node]) | |
ret_list.append(node) | |
map(lambda n: _visit(n, []), dag.keys()) | |
return ret_list | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment