toposort#

Topological sorting implementation.

Functions#

_toposort(→ collections.abc.Iterator[T])

Dependencies are expressed as a dictionary whose keys are items

pop_key(→ T)

Pop an item from the graph that has the fewest dependencies in the case of a tie

_safe_toposort(→ collections.abc.Iterator[T])

Dependencies are expressed as a dictionary whose keys are items

toposort(→ list[T])

Return a topologically sorted list of items from a dependency graph.

Attributes#

T

T#
_toposort(data: dict[T, set[T]]) collections.abc.Iterator[T]#

Dependencies are expressed as a dictionary whose keys are items and whose values are a set of dependent items. Output is a list of sets in topological order. The first set consists of items with no dependences, each subsequent set consists of items that depend upon items in the preceding sets.

pop_key(data: dict[T, set[T]]) T#

Pop an item from the graph that has the fewest dependencies in the case of a tie The winners will be sorted alphabetically

_safe_toposort(data: dict[T, set[T]]) collections.abc.Iterator[T]#

Dependencies are expressed as a dictionary whose keys are items and whose values are a set of dependent items. Output is a list of sets in topological order. The first set consists of items with no dependencies, each subsequent set consists of items that depend upon items in the preceding sets.

toposort(data: collections.abc.Mapping[T, collections.abc.Iterable[T]], safe: bool = True) list[T]#

Return a topologically sorted list of items from a dependency graph.

Dependencies are expressed as a mapping whose keys are items and whose values are an iterable of dependent items.