parameters: (split_contexts_by_name)
docstring: Moves jars used by multiple splits into common ancestors.
  
    Updates |input_jars| for each _SplitContext.
docstring_summary: Moves jars used by multiple splits into common ancestors.
docstring_tokens: Moves jars used by multiple splits into common ancestors .
function: def _DeDupeInputJars(split_contexts_by_name):
    """Moves jars used by multiple splits into common ancestors.
  
    Updates |input_jars| for each _SplitContext.
    """
  
    def count_ancestors(split_context):
      ret = 0
      if split_context.parent_name:
        ret += 1
        ret += count_ancestors(split_contexts_by_name[split_context.parent_name])
      return ret
  
    base_context = split_contexts_by_name['base']
    # Sort by tree depth so that ensure children are visited before their parents.
    sorted_contexts = list(split_contexts_by_name.values())
    sorted_contexts.remove(base_context)
    sorted_contexts.sort(key=count_ancestors, reverse=True)
  
    # If a jar is present in multiple siblings, promote it to their parent.
    seen_jars_by_parent = defaultdict(set)
    for split_context in sorted_contexts:
      seen_jars = seen_jars_by_parent[split_context.parent_name]
      new_dupes = seen_jars.intersection(split_context.input_jars)
      parent_context = split_contexts_by_name[split_context.parent_name]
      parent_context.input_jars.update(new_dupes)
      seen_jars.update(split_context.input_jars)
  
    def ancestor_jars(parent_name, dest=None):
      dest = dest or set()
      if not parent_name:
        return dest
      parent_context = split_contexts_by_name[parent_name]
      dest.update(parent_context.input_jars)
      return ancestor_jars(parent_context.parent_name, dest)
  
    # Now that jars have been moved up the tree, remove those that appear in
    # ancestors.
    for split_context in sorted_contexts:
      split_context.input_jars -= ancestor_jars(split_context.parent_name)
function_tokens: def _DeDupeInputJars ( split_contexts_by_name ) : def count_ancestors ( split_context ) : ret = 0 if split_context . parent_name : ret += 1 ret += count_ancestors ( split_contexts_by_name [ split_context . parent_name ] ) return ret base_context = split_contexts_by_name [ 'base' ] # Sort by tree depth so that ensure children are visited before their parents. sorted_contexts = list ( split_contexts_by_name . values ( ) ) sorted_contexts . remove ( base_context ) sorted_contexts . sort ( key = count_ancestors , reverse = True ) # If a jar is present in multiple siblings, promote it to their parent. seen_jars_by_parent = defaultdict ( set ) for split_context in sorted_contexts : seen_jars = seen_jars_by_parent [ split_context . parent_name ] new_dupes = seen_jars . intersection ( split_context . input_jars ) parent_context = split_contexts_by_name [ split_context . parent_name ] parent_context . input_jars . update ( new_dupes ) seen_jars . update ( split_context . input_jars ) def ancestor_jars ( parent_name , dest = None ) : dest = dest or set ( ) if not parent_name : return dest parent_context = split_contexts_by_name [ parent_name ] dest . update ( parent_context . input_jars ) return ancestor_jars ( parent_context . parent_name , dest ) # Now that jars have been moved up the tree, remove those that appear in # ancestors. for split_context in sorted_contexts : split_context . input_jars -= ancestor_jars ( split_context . parent_name )