function mappingToExists(existings, newCmptOptions, mode) {
  var isNormalMergeMode = mode === 'normalMerge';
  var isReplaceMergeMode = mode === 'replaceMerge';
  var isReplaceAllMode = mode === 'replaceAll';
  existings = existings || [];
  newCmptOptions = (newCmptOptions || []).slice();
  var existingIdIdxMap = createHashMap(); // Validate id and name on user input option.

  each(newCmptOptions, function (cmptOption, index) {
    if (!isObject(cmptOption)) {
      newCmptOptions[index] = null;
      return;
    }

    if (true) {
      // There is some legacy case that name is set as `false`.
      // But should work normally rather than throw error.
      if (cmptOption.id != null && !isValidIdOrName(cmptOption.id)) {
        warnInvalidateIdOrName(cmptOption.id);
      }

      if (cmptOption.name != null && !isValidIdOrName(cmptOption.name)) {
        warnInvalidateIdOrName(cmptOption.name);
      }
    }
  });
  var result = prepareResult(existings, existingIdIdxMap, mode);

  if (isNormalMergeMode || isReplaceMergeMode) {
    mappingById(result, existings, existingIdIdxMap, newCmptOptions);
  }

  if (isNormalMergeMode) {
    mappingByName(result, newCmptOptions);
  }

  if (isNormalMergeMode || isReplaceMergeMode) {
    mappingByIndex(result, newCmptOptions, isReplaceMergeMode);
  } else if (isReplaceAllMode) {
    mappingInReplaceAllMode(result, newCmptOptions);
  }

  makeIdAndName(result); // The array `result` MUST NOT contain elided items, otherwise the
  // forEach will ommit those items and result in incorrect result.

  return result;
}
Mapping to existings for merge.

Mode "normalMege":
    The mapping result (merge result) will keep the order of the existing
    component, rather than the order of new option. Because we should ensure
    some specified index reference (like xAxisIndex) keep work.
    And in most cases, "merge option" is used to update partial option but not
    be expected to change the order.

Mode "replaceMege":
    (1) Only the id mapped components will be merged.
    (2) Other existing components (except internal compoonets) will be removed.
    (3) Other new options will be used to create new component.
    (4) The index of the existing compoents will not be modified.
    That means their might be "hole" after the removal.
    The new components are created first at those available index.

Mode "replaceAll":
    This mode try to support that reproduce an echarts instance from another
    echarts instance (via `getOption`) in some simple cases.
    In this senario, the `result` index are exactly the consistent with the `newCmptOptions`,
    which ensures the compoennt index referring (like `xAxisIndex: ?`) corrent. That is,
    the "hole" in `newCmptOptions` will also be kept.
    On the contrary, other modes try best to eliminate holes.
    PENDING: This is an experimental mode yet.

@return See the comment of <MappingResult>.