Part of bzrlib.tsort View In Hierarchy

No class docstring

Method | __init__ | Topological sorting of a graph. |

Method | sorted | Sort the graph and return as a list. |

Method | iter_topo_order | Yield the nodes of the graph in a topological order. |

def
__init__(self, graph):

Topological sorting of a graph.

node identifiers can be any hashable object, and are typically strings.

If you have a graph like [('a', ['b']), ('a', ['c'])] this will only use one of the two values for 'a'.

The graph is sorted lazily: until you iterate or sort the input is not processed other than to create an internal representation.

iteration or sorting may raise GraphCycleError if a cycle is present in the graph.

Parameters | graph | sequence of pairs of node_name->parent_names_list. i.e. [('C', ['B']), ('B', ['A']), ('A', [])] For this input the output from the sort or iter_topo_order routines will be: 'A', 'B', 'C' |