tools/media_engagement_preload/make_dafsa.py
def top_sort(dafsa):
  """Generates list of nodes in topological sort order."""
  incoming = {}

  def count_incoming(node):
    """Counts incoming references."""
    if node:
      if id(node) not in incoming:
        incoming[id(node)] = 1
        for child in node[1]:
          count_incoming(child)
      else:
        incoming[id(node)] += 1

  for node in dafsa:
    count_incoming(node)

  for node in dafsa:
    incoming[id(node)] -= 1

  waiting = [node for node in dafsa if incoming[id(node)] == 0]
  nodes = []

  while waiting:
    node = waiting.pop()
    assert incoming[id(node)] == 0
    nodes.append(node)
    for child in node[1]:
      if child:
        incoming[id(child)] -= 1
        if incoming[id(child)] == 0:
          waiting.append(child)
  return nodes
Generates list of nodes in topological sort order.
Generates list of nodes in topological sort order.
Generates list of nodes in topological sort order .
def top_sort(dafsa):
  incoming = {}
  def count_incoming(node):
    if node:
      if id(node) not in incoming:
        incoming[id(node)] = 1
        for child in node[1]:
          count_incoming(child)
      else:
        incoming[id(node)] += 1
  for node in dafsa:
    count_incoming(node)
  for node in dafsa:
    incoming[id(node)] -= 1
  waiting = [node for node in dafsa if incoming[id(node)] == 0]
  nodes = []
  while waiting:
    node = waiting.pop()
    assert incoming[id(node)] == 0
    nodes.append(node)
    for child in node[1]:
      if child:
        incoming[id(child)] -= 1
        if incoming[id(child)] == 0:
          waiting.append(child)
  return nodes
def top_sort ( dafsa ) : incoming = { } def count_incoming ( node ) : """Counts incoming references.""" if node : if id ( node ) not in incoming : incoming [ id ( node ) ] = 1 for child in node [ 1 ] : count_incoming ( child ) else : incoming [ id ( node ) ] += 1 for node in dafsa : count_incoming ( node ) for node in dafsa : incoming [ id ( node ) ] -= 1 waiting = [ node for node in dafsa if incoming [ id ( node ) ] == 0 ] nodes = [ ] while waiting : node = waiting . pop ( ) assert incoming [ id ( node ) ] == 0 nodes . append ( node ) for child in node [ 1 ] : if child : incoming [ id ( child ) ] -= 1 if incoming [ id ( child ) ] == 0 : waiting . append ( child ) return nodes
Generates list of nodes in topological sort order.
Generates list of nodes in topological sort order .
"""Generates list of nodes in topological sort order.""" """Counts incoming references."""
dafsa