code: def _collect_names(exp_states: Iterable["ExpState"]) -> _DataNames:
      result = _DataNames(defaultdict(dict), defaultdict(dict), set())
  
      def _collect_d(
          result_d: Dict[str, Dict[str, Any]], data_d: Dict[str, Any]
      ):
          for path, item in data_d.items():
              item = item.get("data", {})
              if isinstance(item, dict):
                  item = flatten(item)
                  result_d[path].update((key, None) for key in item)
  
      for exp in exp_states:
          if exp.data:
              _collect_d(result.metrics, exp.data.metrics)
              _collect_d(result.params, exp.data.params)
              result.deps.update(exp.data.deps)
          if exp.experiments:
              for child in exp.experiments:
                  result.update(_collect_names(child.revs))
  
      return result
  
imports: from collections import Counter, defaultdict
  from datetime import date, datetime
  from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, List, Literal, Mapping, NamedTuple, Optional, Set, Tuple, Union
  from dvc.exceptions import InvalidArgumentError
  from dvc.log import logger
  from dvc.scm import Git
  from dvc.ui import ui
  from dvc.utils.flatten import flatten
  from .collect import collect
label_desc: Use image node_id 9 for calling a global function with example usage: _collect_names(exp_states) and returns: result