def _get_span_to_nodes_maps(root_node):
  """Return maps of span indexes to nodes."""
  node_stack = [root_node]
  seen_fingerprints = set()
  span_to_production_nodes = collections.defaultdict(list)
  span_to_aggregation_nodes = collections.defaultdict(list)
  while node_stack:
    node = node_stack.pop()
    fingerprint = _get_node_fingerprint(node)
    if fingerprint in seen_fingerprints:
      continue
    seen_fingerprints.add(fingerprint)

    if isinstance(node, parsing_utils.AggregationNode):
      for child in node.children:
        node_stack.append(child)
      span_to_aggregation_nodes[(node.span_begin, node.span_end)].append(node)
    elif isinstance(node, parsing_utils.RuleApplicationNode):
      for child in node.children:
        node_stack.append(child)
      span_to_production_nodes[(node.span_begin, node.span_end)].append(node)
    else:
      raise ValueError("Unexpected node type.")
  return span_to_production_nodes, span_to_aggregation_nodes
Return maps of span indexes to nodes.
language/compgen/nqg/model/parser/data/forest_serialization.py