MERGE TWO MAPPINGS, a TAKES PRECEDENCE
558002
def _merge_mapping(a, b):
    
    for name, b_details in b.items():
        a_details = a[literal_field(name)]
        if a_details.properties and not a_details.type:
            a_details.type = "object"
        if b_details.properties and not b_details.type:
            b_details.type = "object"

        if a_details:
            a_details.type = _merge_type[a_details.type][b_details.type]

            if b_details.type in ES_STRUCT:
                _merge_mapping(a_details.properties, b_details.properties)
        else:
            a[literal_field(name)] = deepcopy(b_details)

    return a
977023
def update_mapping(self, mapping: Dict[ops.Qid, LogicalIndex],
                       keys: Sequence[ops.Qid]
                       ) -> None:
        
        permutation = self.permutation()
        indices = tuple(permutation.keys())
        new_keys = [keys[permutation[i]] for i in indices]
        old_elements = [mapping[keys[i]] for i in indices]
        mapping.update(zip(new_keys, old_elements))
88863
function normalizeMappings(mappings) {
        if (Array.isArray(mappings)) {
            return mappings.reduce(function (normalizedMappings, key) {
                normalizedMappings[key] = key;

                return normalizedMappings;
            }, {});
        }

        return mappings;
    }
529445
function compareMappingsDeep(mapping1, mapping2) {
  return _.isEqualWith(mapping1, mapping2, (object1, object2, prop) => {
    let mapping1 = { [prop]: object1 }
    let mapping2 = { [prop]: object2 }
    if (prop == "from" || prop == "to") {
      if (!_.isEqual(Object.getOwnPropertyNames(_.get(object1, prop, {})), Object.getOwnPropertyNames(_.get(object2, prop, {})))) {
        return false
      }
      return _.isEqualWith(conceptsOfMapping(mapping1, prop), conceptsOfMapping(mapping2, prop), (concept1, concept2, index) => {
        if (index != undefined) {
          return compare(concept1, concept2)
        }
        return undefined
      })
    }
    if (prop == "fromScheme" || prop == "toScheme") {
      return compare(object1, object2)
    }
    // Let lodash's isEqual do the comparison
    return undefined
  })
}
996355
private int merge(String[] dst, String[] srcA, int lengthA, Tag[] srcB, int lengthB) {
    int i = 0;
    int ai = 0;
    int bi = 0;

    while (ai < lengthA && bi < lengthB) {
      final String ak = srcA[ai];
      final String av = srcA[ai + 1];
      Tag b = srcB[bi];
      int cmp = ak.compareTo(b.key());
      if (cmp < 0) {
        dst[i++] = ak;
        dst[i++] = av;
        ai += 2;
      } else if (cmp > 0) {
        dst[i++] = b.key();
        dst[i++] = b.value();
        ++bi;
      } else {
        // Newer tags should override, use source B if there are duplicate keys.
        // If source B has duplicates, then use the last value for the given key.
        int j = bi + 1;
        for (; j < lengthB && ak.equals(srcB[j].key()); ++j) {
          b = srcB[j];
        }
        dst[i++] = b.key();
        dst[i++] = b.value();
        bi = j;
        ai += 2; // Ignore
      }
    }

    if (ai < lengthA) {
      System.arraycopy(srcA, ai, dst, i, lengthA - ai);
      i += lengthA - ai;
    } else if (bi < lengthB) {
      i = dedup(srcB, bi, dst, i, lengthB - bi);
    }

    return i;
  }
525086
function mergeField(memo, key){
  var result = {},
    match;

  if(_.isPlainObject(key)){
    result = key;
  }else if(_.isString(key) && (match = key.match(re.RENAME))){
    result[match[2]] = match[1];
  }else{
    result[key] = null;
  }

  return _.merge(memo, result);
}
229828
public static <K, V> Map<K, V> merge(Map<K, V>... maps) {
        Map<K, V> map = null;
        for (Map<K, V> m : maps) {
            if (map == null) {
                map = m;
            } else if (m != null) {
                map.putAll(m);
            }
        }
        return map;
    }
206352
public void merge(Map<String, Object> map) {
        if (map == null) {
            throw new IllegalArgumentException("Map to merge cannot be null");
        }

        m_properties.putAll(map);
    }
813222
public static MtasSpanSequenceItem merge(MtasSpanSequenceItem item1,
      MtasSpanSequenceItem item2, MtasSpanQuery ignoreQuery,
      Integer maximumIgnoreLength) {
    if (item1 == null || item2 == null) {
      return null;
    } else {
      MtasSpanQuery q1 = item1.getQuery();
      MtasSpanQuery q2 = item2.getQuery();
      boolean optional = item1.optional && item2.optional;
      // first spanRecurrenceQuery
      if (q1 instanceof MtasSpanRecurrenceQuery) {
        MtasSpanRecurrenceQuery rq1 = (MtasSpanRecurrenceQuery) q1;
        // both spanRecurrenceQuery
        if (q2 instanceof MtasSpanRecurrenceQuery) {
          MtasSpanRecurrenceQuery rq2 = (MtasSpanRecurrenceQuery) q2;
          // equal query
          if (rq1.getQuery().equals(rq2.getQuery())) {
            // equal ignoreQuery settings
            boolean checkCondition;
            checkCondition = ignoreQuery != null
                && rq1.getIgnoreQuery() != null;
            checkCondition = checkCondition
                ? ignoreQuery.equals(rq1.getIgnoreQuery()) : false;
            checkCondition = checkCondition
                ? maximumIgnoreLength.equals(rq1.getMaximumIgnoreLength())
                : false;
            checkCondition = checkCondition ? rq2.getIgnoreQuery() != null
                : false;
            checkCondition = checkCondition
                ? ignoreQuery.equals(rq2.getIgnoreQuery()) : false;
            checkCondition = checkCondition
                ? maximumIgnoreLength.equals(rq2.getMaximumIgnoreLength())
                : false;
            if (checkCondition) {
              // at least one optional
              if (item1.optional || item2.optional) {
                int minimum = Math.min(rq1.getMinimumRecurrence(),
                    rq2.getMinimumRecurrence());
                int maximum = rq1.getMaximumRecurrence()
                    + rq2.getMaximumRecurrence();
                // only if ranges match
                if ((rq1.getMaximumRecurrence() + 1) >= rq2
                    .getMinimumRecurrence()
                    && (rq2.getMaximumRecurrence() + 1) >= rq1
                        .getMinimumRecurrence()) {
                  return new MtasSpanSequenceItem(
                      new MtasSpanRecurrenceQuery(rq1.getQuery(), minimum,
                          maximum, ignoreQuery, maximumIgnoreLength),
                      optional);
                }
                // not optional
              } else {
                int minimum = rq1.getMinimumRecurrence()
                    + rq2.getMinimumRecurrence();
                int maximum = rq1.getMaximumRecurrence()
                    + rq2.getMaximumRecurrence();
                // only if ranges match
                if ((rq1.getMaximumRecurrence() + 1) >= rq2
                    .getMinimumRecurrence()
                    && (rq2.getMaximumRecurrence() + 1) >= rq1
                        .getMinimumRecurrence()) {
                  return new MtasSpanSequenceItem(
                      new MtasSpanRecurrenceQuery(rq1.getQuery(), minimum,
                          maximum, ignoreQuery, maximumIgnoreLength),
                      optional);
                }
              }
            }
          }
        } else {
          if (rq1.getQuery().equals(q2)) {
            boolean checkCondition;
            checkCondition = ignoreQuery != null;
            checkCondition &= rq1.getIgnoreQuery() != null;
            checkCondition &= ignoreQuery.equals(rq1.getIgnoreQuery());
            checkCondition &= rq1.getMaximumIgnoreLength() != null;
            checkCondition &= maximumIgnoreLength
                .equals(rq1.getMaximumIgnoreLength());
            if (checkCondition) {
              if (!optional) {
                if (item1.optional) {
                  if (rq1.getMinimumRecurrence() == 1) {
                    return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(
                        q2, 1, rq1.getMaximumRecurrence() + 1, ignoreQuery,
                        maximumIgnoreLength), false);
                  }
                } else if (item2.optional) {
                  return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(
                      q2, rq1.getMinimumRecurrence(),
                      rq1.getMaximumRecurrence() + 1, ignoreQuery,
                      maximumIgnoreLength), false);
                } else {
                  return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(
                      q2, rq1.getMinimumRecurrence() + 1,
                      rq1.getMaximumRecurrence() + 1, ignoreQuery,
                      maximumIgnoreLength), false);
                }
              } else {
                if (rq1.getMinimumRecurrence() == 1) {
                  return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(
                      q2, 1, rq1.getMaximumRecurrence() + 1, ignoreQuery,
                      maximumIgnoreLength), true);
                }
              }
            }
          }
        }
        // second spanRecurrenceQuery
      } else if (q2 instanceof MtasSpanRecurrenceQuery) {
        MtasSpanRecurrenceQuery rq2 = (MtasSpanRecurrenceQuery) q2;
        if (rq2.getQuery().equals(q1)) {
          boolean checkCondition;
          checkCondition = ignoreQuery != null;
          checkCondition &= rq2.getIgnoreQuery() != null;
          checkCondition &= ignoreQuery.equals(rq2.getIgnoreQuery());
          checkCondition &= maximumIgnoreLength
              .equals(rq2.getMaximumIgnoreLength());
          if (checkCondition) {
            if (!optional) {
              if (item1.optional) {
                return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1,
                    rq2.getMinimumRecurrence(), rq2.getMaximumRecurrence() + 1,
                    ignoreQuery, maximumIgnoreLength), false);
              } else if (item2.optional) {
                if (rq2.getMinimumRecurrence() == 1) {
                  return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(
                      q1, 1, rq2.getMaximumRecurrence() + 1, ignoreQuery,
                      maximumIgnoreLength), false);
                }
              } else {
                return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1,
                    rq2.getMinimumRecurrence() + 1,
                    rq2.getMaximumRecurrence() + 1, ignoreQuery,
                    maximumIgnoreLength), false);
              }
            } else {
              if (rq2.getMinimumRecurrence() == 1) {
                return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1,
                    1, rq2.getMaximumRecurrence() + 1, ignoreQuery,
                    maximumIgnoreLength), true);
              }
            }
          }
        }
        // both no spanRecurrenceQuery
      } else if (q1.equals(q2)) {
        // at least one optional
        if (item1.optional || item2.optional) {
          return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1, 1, 2,
              ignoreQuery, maximumIgnoreLength), optional);
        } else {
          return new MtasSpanSequenceItem(new MtasSpanRecurrenceQuery(q1, 2, 2,
              ignoreQuery, maximumIgnoreLength), optional);
        }
      }
      return null;
    }
  }
63074
function mergeSymbolMaps(additionalSymbols?: Object): Object {
  const symbolMap = {}
  symbolMap.symbols = additionalSymbols
    ? { ...defaultSymbolMap.symbols, ...additionalSymbols.symbols }
    : { ...defaultSymbolMap.symbols }

  return symbolMap
}
792837
function mergeQueries(a,b) {
    for(var k in b) {
        if(k in a) {
            if(k === '$and') {
                a[k] = a[k].concat(b[k])
            } else {
                var andOperandA = {}; andOperandA[k] = a[k]
                var andOperandB = {}; andOperandB[k] = b[k]
                var and = {$and:[andOperandA,andOperandB]}
                delete a[k]
                mergeQueries(a,and)
            }
        } else {
            a[k] = b[k]
        }
    }
}
1103662
function _merge(o1, o2) {
    Object.keys(o2).forEach(function (k) {
        if (o1[k] === undefined) {
            o1[k] = o2[k];
        } else {
            if ((typeof (o1[k])) === 'object') {
                _merge(o1[k], o2[k]);
            } else { // Last property wins!
                o1[k] = o2[k];
            }
        }
    });
}
1176758
final protected function mergeMappings(array $mappingsA, array $mappingsB): array
    {
        foreach ($mappingsB as $key => $value) {
            if (isset($mappingsA[$key]) || \array_key_exists($key, $mappingsA)) {
                if (\is_int($key)) {
                    $mappingsA[] = $value;
                } elseif (\is_array($value) && \is_array($mappingsA[$key])) {
                    $mappingsA[$key] = $this->mergeMappings($mappingsA[$key], $value);
                } else {
                    $mappingsA[$key] = $value;
                }
            } else {
                $mappingsA[$key] = $value;
            }
        }

        return $mappingsA;
    }
309847
function mergeIntoWithNoDuplicateKeys(one, two) {
    _invariant(one && two && (typeof one === 'undefined' ? 'undefined' : _typeof(one)) === 'object' && (typeof two === 'undefined' ? 'undefined' : _typeof(two)) === 'object', 'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.');

    for (var key in two) {
      if (two.hasOwnProperty(key)) {
        _invariant(one[key] === undefined, 'mergeIntoWithNoDuplicateKeys(): ' + 'Tried to merge two objects with the same key: `%s`. This conflict ' + 'may be due to a mixin; in particular, this may be caused by two ' + 'getInitialState() or getDefaultProps() methods returning objects ' + 'with clashing keys.', key);
        one[key] = two[key];
      }
    }
    return one;
  }
822517
function copyAndOffsetMapping(existingMapping) {
    var column     = getColumnAfter(existingMapping.generatedLine - 1, existingMapping.generatedColumn);
    var newMapping = {
      generated: {
        line  : existingMapping.generatedLine,
        column: column
      }
    };
    if (existingMapping.source) {
      newMapping.source   = existingMapping.source;
      newMapping.original = {
        line  : existingMapping.originalLine,
        column: existingMapping.originalColumn
      };
      if (existingMapping.name) {
        newMapping.name = existingMapping.name;
      }
    }
    generator.addMapping(newMapping);
  }
438968
private void mergeProperties(Map<ExecutionConfigSource, Map<ExecutionProperty, List<String>>> sourceToPropertiesMap) {
        for ( ExecutionConfigSource s : propertySources) {
            Map<ExecutionProperty, List<String>> properties = sourceToPropertiesMap.get(s);
            for ( ExecutionProperty p : properties.keySet()) {
                List<String> valuesFromSource = properties.get(p);
                if ( valuesFromSource != null && !valuesFromSource.isEmpty()) {
                    List<String> vals = getOrCreatePropertyValues(p);
                    mergeValues(valuesFromSource, p, vals);
                }
            }
        }
    }
1283840
def merge(a, b):
    ""
    for key in b:
        if isinstance(a.get(key), dict) and isinstance(b.get(key), dict):
            merge(a[key], b[key])
        else:
            a[key] = b[key]
    return a