

class Edge(object):
    """
    This class represents edges in the dependency graph.
    """

    def __init__(self, source, sink=None, map=None):
        """
        :param source: source of data
        :param sink: sink of data
        :param map: sequence of name pairs that map source exits to sink
                    entrances
        """
        self.source = source
        self.sink = sink
        self.map = map


from penchy.util import topological_sort


class Edge(object):
    """
    This class represents edges in the dependency graph.
    """

    def __init__(self, source, sink=None, map=None):
        """
        :param source: source of data
        :param sink: sink of data
        :param map: sequence of name pairs that map source exits to sink
                    entrances
        """
        self.source = source
        self.sink = sink
        self.map = map


def edgesort(edges):
    """
    Return the topological sorted elements of ``edges``.

    :param edges: Sequence of :class:`Edge`
    :returns: topological sorted :class:`PipelineElement`
    """
    starts = set(edge.source for edge in edges)
    deps = []
    edges = list(edges)
    while edges:
        target = edges[0].sink
        starts.discard(target)
        sources = [edge.source for edge in edges if edge.sink is target]
        deps.append((sources if sources else None, target))
        edges = [edge for edge in edges if edge.sink is not target]
    deps.extend((None, start) for start in starts)
    return topological_sort(deps)
Add edgesort as a frontend to topological_sort.
Add edgesort as a frontend to topological_sort.

Signed-off-by: Michael Markert <5eb998b7ac86da375651a4cd767b88c9dad25896@googlemail.com>

+ 
+ from penchy.util import topological_sort
  
  
  class Edge(object):
      """
      This class represents edges in the dependency graph.
      """
  
      def __init__(self, source, sink=None, map=None):
          """
          :param source: source of data
          :param sink: sink of data
          :param map: sequence of name pairs that map source exits to sink
                      entrances
          """
          self.source = source
          self.sink = sink
          self.map = map
  
+ 
+ def edgesort(edges):
+     """
+     Return the topological sorted elements of ``edges``.
+ 
+     :param edges: Sequence of :class:`Edge`
+     :returns: topological sorted :class:`PipelineElement`
+     """
+     starts = set(edge.source for edge in edges)
+     deps = []
+     edges = list(edges)
+     while edges:
+         target = edges[0].sink
+         starts.discard(target)
+         sources = [edge.source for edge in edges if edge.sink is target]
+         deps.append((sources if sources else None, target))
+         edges = [edge for edge in edges if edge.sink is not target]
+     deps.extend((None, start) for start in starts)
+     return topological_sort(deps)
Add edgesort as a frontend to topological_sort.
## Code Before:


class Edge(object):
    """
    This class represents edges in the dependency graph.
    """

    def __init__(self, source, sink=None, map=None):
        """
        :param source: source of data
        :param sink: sink of data
        :param map: sequence of name pairs that map source exits to sink
                    entrances
        """
        self.source = source
        self.sink = sink
        self.map = map

## Instruction:
Add edgesort as a frontend to topological_sort.
## Code After:

from penchy.util import topological_sort


class Edge(object):
    """
    This class represents edges in the dependency graph.
    """

    def __init__(self, source, sink=None, map=None):
        """
        :param source: source of data
        :param sink: sink of data
        :param map: sequence of name pairs that map source exits to sink
                    entrances
        """
        self.source = source
        self.sink = sink
        self.map = map


def edgesort(edges):
    """
    Return the topological sorted elements of ``edges``.

    :param edges: Sequence of :class:`Edge`
    :returns: topological sorted :class:`PipelineElement`
    """
    starts = set(edge.source for edge in edges)
    deps = []
    edges = list(edges)
    while edges:
        target = edges[0].sink
        starts.discard(target)
        sources = [edge.source for edge in edges if edge.sink is target]
        deps.append((sources if sources else None, target))
        edges = [edge for edge in edges if edge.sink is not target]
    deps.extend((None, start) for start in starts)
    return topological_sort(deps)