home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
-
- def topological_sort(items, partial_order):
-
- def add_node(graph, node):
- if not graph.has_key(node):
- graph[node] = [
- 0]
-
-
-
- def add_arc(graph, fromnode, tonode):
- graph[fromnode].append(tonode)
- graph[tonode][0] = graph[tonode][0] + 1
-
- graph = { }
- for v in items:
- add_node(graph, v)
-
- for a, b in partial_order:
- add_arc(graph, a, b)
-
- roots = _[1]
- sorted = []
- while len(roots) != 0:
- root = roots.pop()
- sorted.append(root)
- for child in graph[root][1:]:
- graph[child][0] = graph[child][0] - 1
- if graph[child][0] == 0:
- roots.append(child)
- continue
- []
-
- del graph[root]
- continue
- []
- if len(graph.items()) != 0:
- return None
- return sorted
-
-
- def topological_sort_chains(chains):
-
- def add_node(graph, node):
- if not graph.has_key(node):
- graph[node] = [
- 0]
-
-
-
- def add_arc(graph, fromnode, tonode):
- graph[fromnode].append(tonode)
- graph[tonode][0] = graph[tonode][0] + 1
-
- graph = { }
- for chain in chains:
- if not len(chain):
- continue
-
- add_node(graph, chain[0])
- for i in range(len(chain) - 1):
- add_node(graph, chain[i + 1])
- add_arc(graph, chain[i], chain[i + 1])
-
-
- oset = oset
- import structures
- total = oset()
- for chain in chains:
- total.update(chain)
-
- roots = [](_[1])
- roots = list(total & roots)
- sorted = []
- while len(roots) != 0:
- root = roots.pop(0)
- sorted.append(root)
- newroots = []
- for child in graph[root][1:]:
- graph[child][0] = graph[child][0] - 1
- if graph[child][0] == 0:
- newroots.append(child)
- continue
- []
-
- roots = newroots + roots
- del graph[root]
- continue
- oset
- if len(graph.items()) != 0:
- return None
- return sorted
-
-