tools/media_engagement_preload/make_dafsa.py
def reverse(dafsa):
  """Generates a new DAFSA that is reversed, so that the old sink node becomes
  the new source node.
  """
  sink = []
  nodemap = {}

  def dfs(node, parent):
    """Creates reverse nodes.

    A new reverse node will be created for each old node. The new node will
    get a reversed label and the parents of the old node as children.
    """
    if not node:
      sink.append(parent)
    elif id(node) not in nodemap:
      nodemap[id(node)] = (node[0][::-1], [parent])
      for child in node[1]:
        dfs(child, nodemap[id(node)])
    else:
      nodemap[id(node)][1].append(parent)

  for node in dafsa:
    dfs(node, None)
  return sink
Generates a new DAFSA that is reversed, so that the old sink node becomes
  the new source node.
  
Generates a new DAFSA that is reversed, so that the old sink node becomes
the new source node.
Generates a new DAFSA that is reversed so that the old sink node becomes the new source node .
def reverse(dafsa):
  sink = []
  nodemap = {}
  def dfs(node, parent):
    if not node:
      sink.append(parent)
    elif id(node) not in nodemap:
      nodemap[id(node)] = (node[0][::-1], [parent])
      for child in node[1]:
        dfs(child, nodemap[id(node)])
    else:
      nodemap[id(node)][1].append(parent)
  for node in dafsa:
    dfs(node, None)
  return sink
def reverse ( dafsa ) : sink = [ ] nodemap = { } def dfs ( node , parent ) : """Creates reverse nodes.

    A new reverse node will be created for each old node. The new node will
    get a reversed label and the parents of the old node as children.
    """ if not node : sink . append ( parent ) elif id ( node ) not in nodemap : nodemap [ id ( node ) ] = ( node [ 0 ] [ : : - 1 ] , [ parent ] ) for child in node [ 1 ] : dfs ( child , nodemap [ id ( node ) ] ) else : nodemap [ id ( node ) ] [ 1 ] . append ( parent ) for node in dafsa : dfs ( node , None ) return sink
Generates a new DAFSA that is reversed, so that the old sink node becomes
the new source node.
Generates a new DAFSA that is reversed so that the old sink node becomes the new source node .
"""Generates a new DAFSA that is reversed, so that the old sink node becomes
  the new source node.
  """ """Creates reverse nodes.

    A new reverse node will be created for each old node. The new node will
    get a reversed label and the parents of the old node as children.
    """
dafsa