def _get_sorted_nodes(root_node):
  """Returns list of nodes sorted by order (ties broken by traversal order)."""
  node_stack = [root_node]
  seen_fingerprints = set()
  order_to_nodes_map = 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)
    order_to_nodes_map[node.order].append(node)
    for child in node.children:
      node_stack.append(child)

  orders = sorted(order_to_nodes_map.keys())
  sorted_nodes = []
  for order in orders:
    sorted_nodes.extend(order_to_nodes_map[order])
  return sorted_nodes
Returns list of nodes sorted by order (ties broken by traversal order).
language/compgen/csl/model/data/forest_serialization.py