Merge two trees together The roots of tree1 and tree2 must be the same revision
972957
function mergeTree(in_tree1, in_tree2) {
  var queue = [{tree1: in_tree1, tree2: in_tree2}];
  var conflicts = false;
  while (queue.length > 0) {
    var item = queue.pop();
    var tree1 = item.tree1;
    var tree2 = item.tree2;

    if (tree1[1].status || tree2[1].status) {
      tree1[1].status =
        (tree1[1].status ===  'available' ||
        tree2[1].status === 'available') ? 'available' : 'missing';
    }

    for (var i = 0; i < tree2[2].length; i++) {
      if (!tree1[2][0]) {
        conflicts = 'new_leaf';
        tree1[2][0] = tree2[2][i];
        continue;
      }

      var merged = false;
      for (var j = 0; j < tree1[2].length; j++) {
        if (tree1[2][j][0] === tree2[2][i][0]) {
          queue.push({tree1: tree1[2][j], tree2: tree2[2][i]});
          merged = true;
        }
      }
      if (!merged) {
        conflicts = 'new_branch';
        insertSorted(tree1[2], tree2[2][i], compareTree);
      }
    }
  }
  return {conflicts: conflicts, tree: in_tree1};
}
651921
def replace_nodes(root, old, new):

    '''
     
    '''

    rep = Replacer(old, new)
    rep.visit(root)
    return
122987
def merge(subtree, prefix, name, options = {})
      register(prefix, name, options)
      subtree.calls.each do |key, command|
        next unless command

        calls["#{prefix}#{key}"] = command
      end
    end
996470
def merge(directory, message, branch_label, rev_id, revisions):
    """"""
    _merge(directory, revisions, message, branch_label, rev_id)
557720
def union(self, label_a, label_b):
        
        # Base case to avoid work
        if label_a == label_b:
            return

        # Find the tree root of each node
        root_a = self.find(label_a)
        root_b = self.find(label_b)

        # Avoid merging a tree to itself
        if root_a == root_b:
            return

        self.__internal_union(root_a, root_b)
        self.__set_counter -= 1
667002
function merge(obj1, obj2) {
  var res = {}, attrname;

  for (attrname in obj1) {
    res[attrname] = obj1[attrname];
  }
  for (attrname in obj2) {
    res[attrname] = obj2[attrname];
  }
  return res;
}
652506
def pair_tree_creator(meta_id):
    """"""
    chunks = []
    for x in range(0, len(meta_id)):
        if x % 2:
            continue
        if (len(meta_id) - 1) == x:
            chunk = meta_id[x]
        else:
            chunk = meta_id[x: x + 2]
        chunks.append(chunk)
    return os.sep + os.sep.join(chunks) + os.sep
1014949
def prune_tree_for_supertree(self,
                                 ott,
                                 to_prune_fsi_set,
                                 root_ott_id,
                                 taxonomy_treefile=None,
                                 id_to_other_prune_reason=None):
        
        if id_to_other_prune_reason is None:
            id_to_other_prune_reason = {}
        self.prune_to_ingroup()
        self.prune_unmapped_leaves()
        other_pruned = set()
        if id_to_other_prune_reason:
            id2p = set(id_to_other_prune_reason.keys()).intersection(set(self.by_ott_id.keys()))
            for ott_id in id2p:
                reason = id_to_other_prune_reason[ott_id]
                self.prune_ott_problem_leaves_by_id(ott_id, reason)
        # Check the stored OTT Ids against the current version of OTT
        mapped, unrecog, forward2unrecog, pruned, above_root, old2new = ott.map_ott_ids(self.by_ott_id.keys(),
                                                                                        to_prune_fsi_set, root_ott_id)
        for ott_id in unrecog:
            self.prune_ott_problem_leaves_by_id(ott_id, 'unrecognized_ott_id')
        for ott_id in forward2unrecog:
            self.prune_ott_problem_leaves_by_id(ott_id, 'forwarded_to_unrecognized_ott_id')
        for ott_id in pruned:
            self.prune_ott_problem_leaves_by_id(ott_id, 'flagged')
        for ott_id in above_root:
            self.prune_ott_problem_leaves_by_id(ott_id, 'above_root')
        for old_id, new_id in old2new.items():
            old_node_list = self.by_ott_id[old_id]
            del self.by_ott_id[old_id]
            if new_id in self.by_ott_id:
                v = self.by_ott_id[new_id]
                v.extend(old_node_list)
                v.sort() # I think only the last step requires sorting (NEED to check that,
                         # If so, we could move this sort to that point to avoid multiple sortings.
            else:
                self.by_ott_id[new_id] = old_node_list
            for sortable_el in old_node_list:
                otu = sortable_el[3]
                assert otu['^ot:ottId'] == old_id
                otu['^ot:ottId'] = new_id
                assert '^ot:ottTaxonName' in otu
                otu['^ot:ottTaxonName'] = ott.get_name(new_id)
        lost_tips = set(unrecog)
        lost_tips.update(forward2unrecog)
        lost_tips.update(pruned)
        lost_tips.update(other_pruned)
        # Get the induced tree...
        assert self.root_node_id
        try:
            ott_tree = ott.induced_tree(mapped, create_monotypic_nodes=True)
        except SpikeTreeError:
            error('SpikeTreeError from mapped ott_id list = {}'.format(', '.join([str(i) for i in mapped])))
            raise EmptyTreeError()
        if taxonomy_treefile is not None:
            with codecs.open(taxonomy_treefile, 'w', encoding='utf-8') as tto:
                ott_tree.write_newick(tto)
        # ... so that we can look for leaves mapped to ancestors of other leaves
        taxon_contains_other_ott_ids = []
        to_retain = []
        for ott_id in self.by_ott_id:
            if ott_id in lost_tips:
                continue
            n = old2new.get(ott_id)
            if n is None:
                n = ott_id
            nd = ott_tree.find_node(n)
            assert nd is not None
            if nd.children:
                # nd must be an internal node.
                #   given that the descendants of this node are mapped in a more specific
                #   way, we will prune this ott_id from the tree
                taxon_contains_other_ott_ids.append(ott_id)
            else:
                to_retain.append(ott_id)

        for ott_id in taxon_contains_other_ott_ids:
            self.prune_ott_problem_leaves_by_id(ott_id, 'mapped_to_taxon_containing_other_mapped_tips')
        # finally, we walk through any ott_id's mapped to multiple nodes
        for ott_id in to_retain:
            nm = self.by_ott_id[ott_id]
            if len(nm) > 1:
                el = nm.pop(0)
                reason = 'replaced_by_exemplar_node' if (el[0] == -1) else 'replaced_by_arbitrary_node'
                self.prune_ott_problem_leaves_by_id(ott_id, reason)
        return self
1115536
private List<Path> mergeRoots(Path[] dupRoots) {
    sortPathByDepth(dupRoots);
    List<Path> roots = new ArrayList<Path>();
    
    for (Path candidate : dupRoots) {
      boolean shouldAdd = true;
      for (Path root : roots) {
        if (isAncestorPath(root.toUri().getPath(), 
            candidate.toUri().getPath())) {
          shouldAdd = false;
          break;
        }
      }
      
      if (shouldAdd) {
        roots.add(candidate);
      }
    }
    return roots;
  }
493177
def merge_errors(errors1, errors2):
    
    if not errors1:
        return errors2
    if not errors2:
        return errors1
    if isinstance(errors1, list):
        if isinstance(errors2, list):
            return errors1 + errors2
        if isinstance(errors2, dict):
            return dict(
                errors2,
                **{SCHEMA: merge_errors(errors1, errors2.get(SCHEMA))}
            )
        return errors1 + [errors2]
    if isinstance(errors1, dict):
        if isinstance(errors2, list):
            return dict(
                errors1,
                **{SCHEMA: merge_errors(errors1.get(SCHEMA), errors2)}
            )
        if isinstance(errors2, dict):
            errors = dict(errors1)
            for key, val in iteritems(errors2):
                if key in errors:
                    errors[key] = merge_errors(errors[key], val)
                else:
                    errors[key] = val
            return errors
        return dict(
            errors1,
            **{SCHEMA: merge_errors(errors1.get(SCHEMA), errors2)}
        )
    if isinstance(errors2, list):
        return [errors1] + errors2 if errors2 else errors1
    if isinstance(errors2, dict):
        return dict(
            errors2,
            **{SCHEMA: merge_errors(errors1, errors2.get(SCHEMA))}
        )
    return [errors1, errors2]
962355
function merge(visitors) {
  var rootVisitor = {};

  var _arr5 = visitors;
  for (var _i5 = 0; _i5 < _arr5.length; _i5++) {
    var visitor = _arr5[_i5];
    explode(visitor);

    for (var type in visitor) {
      var nodeVisitor = rootVisitor[type] = rootVisitor[type] || {};
      mergePair(nodeVisitor, visitor[type]);
    }
  }

  return rootVisitor;
}
1199581
public Env<A> dup(JCTree tree, A info) {
        return dupto(new Env<>(tree, info));
    }
269743
def compare_trees(dir1, dir2):
    """"""
    paths1 = DirPaths(dir1).walk()
    paths2 = DirPaths(dir2).walk()
    return unique_venn(paths1, paths2)
804897
protected Node<K, V> unionWithComparator(Node<K, V> root1, Node<K, V> root2) {
        if (root1 == null) {
            return root2;
        } else if (root2 == null) {
            return root1;
        }

        Node<K, V> newRoot;
        Node<K, V> cur;

        // find initial
        int c = comparator.compare(root1.key, root2.key);
        if (c <= 0) {
            newRoot = root1;
            root1 = unlinkRightChild(root1);
        } else {
            newRoot = root2;
            root2 = unlinkRightChild(root2);
        }
        cur = newRoot;

        // merge
        while (root1 != null && root2 != null) {
            c = comparator.compare(root1.key, root2.key);
            if (c <= 0) {
                // link as left child of cur
                if (cur.o_c == null) {
                    root1.y_s = cur;
                } else {
                    root1.y_s = cur.o_c;
                }
                cur.o_c = root1;
                cur = root1;
                root1 = unlinkRightChild(root1);
            } else {
                // link as left child of cur
                if (cur.o_c == null) {
                    root2.y_s = cur;
                } else {
                    root2.y_s = cur.o_c;
                }
                cur.o_c = root2;
                cur = root2;
                root2 = unlinkRightChild(root2);
            }
        }

        while (root1 != null) {
            // link as left child of cur
            if (cur.o_c == null) {
                root1.y_s = cur;
            } else {
                root1.y_s = cur.o_c;
            }
            cur.o_c = root1;
            cur = root1;
            root1 = unlinkRightChild(root1);
        }

        while (root2 != null) {
            // link as left child of cur
            if (cur.o_c == null) {
                root2.y_s = cur;
            } else {
                root2.y_s = cur.o_c;
            }
            cur.o_c = root2;
            cur = root2;
            root2 = unlinkRightChild(root2);
        }

        return newRoot;
    }
1163176
def merge_configs(a, b, copy_trees=False):
        
        for key, value in b.items():
            # if key is in both a and b and both values are dictionary then merge it otherwise override it
            if key in a and isinstance(a[key], ConfigTree) and isinstance(b[key], ConfigTree):
                if copy_trees:
                    a[key] = a[key].copy()
                ConfigTree.merge_configs(a[key], b[key], copy_trees=copy_trees)
            else:
                if isinstance(value, ConfigValues):
                    value.parent = a
                    value.key = key
                    if key in a:
                        value.overriden_value = a[key]
                a[key] = value
                if a.root:
                    if b.root:
                        a.history[key] = a.history.get(key, []) + b.history.get(key, [value])
                    else:
                        a.history[key] = a.history.get(key, []) + [value]

        return a
122735
protected void mergeRegions() {

		// sort edges
//		long time0 = System.currentTimeMillis();
		if( sorterApprox != null ) {
			sorterApprox.computeRange(edges.data,0,edges.size);
			sorterApprox.sortObject(edges.data,0,edges.size);
		} else {
			sorter.sort(edges.data,edges.size);
		}
//		long time1 = System.currentTimeMillis();

//		System.out.println("Sort time " + (time1 - time0));

		// examine each edge to see if it can connect two regions
		for( int i = 0; i < edges.size(); i++ ) {
			// compare the two nodes connected by the edge to see if their regions they should be merged
			Edge e = edges.get(i);

			int rootA = find(e.indexA);
			int rootB = find(e.indexB);

			// see if they are already part of the same segment
			if( rootA == rootB )
				continue;

			float threshA = threshold.get(rootA);
			float threshB = threshold.get(rootB);

			if( e.weight() <= threshA && e.weight() <= threshB )  {
				// ----- Merge the two regions/components
				int sizeA = regionSize.get(rootA);
				int sizeB = regionSize.get(rootB);

				// Everything is merged into region A, so update its threshold
				threshold.data[rootA] = e.weight() + K/(sizeA + sizeB);

				// Point everything towards rootA
				graph.data[e.indexB] = rootA;
				graph.data[rootB] = rootA;

				// Update the size of regionA
				regionSize.data[rootA] = sizeA + sizeB;
			} else {
				edgesNotMatched.add(e);
			}
		}

//		long time2 = System.currentTimeMillis();
//		System.out.println("Edge merge time " + (time2 - time1));
	}
77194
def merge(self):
        """"""
        if isinstance(self.head, dict) and isinstance(self.update, dict):
            if not isinstance(self.root, dict):
                self.root = {}
            self._merge_dicts()
        else:
            self._merge_base_values()

        if self.conflict_set:
            raise MergeError('Dictdiffer Errors', self.conflicts)