code: def _toposort(edges):
      """Topological sort algorithm by Kahn [1] - O(nodes + vertices)
  
      inputs:
          edges - a dict of the form {a: {b, c}} where b and c depend on a
      outputs:
          L - an ordered list of nodes that satisfy the dependencies of edges
  
      >>> _toposort({1: (2, 3), 2: (3, )})
      [1, 2, 3]
  
      Closely follows the wikipedia page [2]
  
      [1] Kahn, Arthur B. (1962), "Topological sorting of large networks",
      Communications of the ACM
      [2] http://en.wikipedia.org/wiki/Toposort#Algorithms
      """
      incoming_edges = reverse_dict(edges)
      incoming_edges = dict(
          (k, set(val)) for k, val in incoming_edges.items()
      )
      S = set((v for v in edges if v not in incoming_edges))
      L = []
  
      while S:
          n = S.pop()
          L.append(n)
          for m in edges.get(n, ()):
              assert n in incoming_edges[m]
              incoming_edges[m].remove(n)
              if not incoming_edges[m]:
                  S.add(m)
      if any(incoming_edges.get(v) for v in edges):
          raise ValueError("Input has cycles")
      return L
  
file_path: datashader/datashader/datashape/internal_utils.py
imports: from __future__ import print_function, division, absolute_import
  import keyword
  import re
label_desc: Use image node_id 3 for calling a global function with example usage: _toposort(edges) and returns: L