Unifies the tree rooted in node1 with the tree rooted in
node2, by making one of them the subtree of the other one;
returns the root of the new tree.
779535
private Node<E> _link(Node<E> node1, Node<E> node2) {
	// maybe there is no real unification here
	if(node1 == node2) return node2;
	// from now on, we know that we unify really disjoint trees
	if(node1.rank > node2.rank) {
	    node2.parent = node1;
	    node1.nbElems += node2.nbElems; 
	    return node1;
	}
	else {
	    node1.parent = node2;
	    if (node1.rank == node2.rank) {
		node2.rank++;
	    }
	    node2.nbElems += node1.nbElems;
	    return node2;
	}
    }
603000
@Override
    public TreeNode processMerge(TreeNode node) {

        DefaultMutableTreeNode masterNode = (DefaultMutableTreeNode) node;

        // if master and slave are the same object return the
        // masterNode
        if (masterNode.equals(slaveTopNode)) {
            return masterNode;
        }

        // If there are not children in slaveTopNode return the
        // masterNode
        if (slaveTopNode.getChildCount() == 0) {
            return masterNode;
        }

        mergeNodes(masterNode, slaveTopNode);
        return masterNode;
    }
809852
private static Rectangle2d union(AbstractGISTreeSetNode<?, ?> node, Rectangle2afp<?, ?, ?, ?, ?, ?> shape) {
		final Rectangle2d b = getNodeBuildingBounds(node);
		b.setUnion(shape);
		normalize(b, shape);
		return b;
	}
731904
public V merge(V a, V b) {
        final V aHead = componentOf(a);
        final V bHead = componentOf(b);
        if (aHead.equals(bHead)) return aHead;
        // add the shorter tree underneath the taller tree
        final int aRank = ranks.getOrDefault(aHead, 0);
        final int bRank = ranks.getOrDefault(bHead, 0);
        if (aRank > bRank) {
            parents.put(bHead, aHead);
            return aHead;
        } else if (bRank > aRank) {
            parents.put(aHead, bHead);
            return bHead;
        } else {
            // whoops, the tree got taller
            parents.put(bHead, aHead);
            ranks.put(aHead, aRank + 1);
            return aHead;
        }
    }
866757
private static List<JoinNode> generateInnerJoinOrdersForTree(JoinNode subTree) {
        // Get a list of the leaf nodes(tables) to permute them
        List<JoinNode> tableNodes = subTree.generateLeafNodesJoinOrder();
        List<List<JoinNode>> joinOrders = PermutationGenerator.generatePurmutations(tableNodes);
        List<JoinNode> newTrees = new ArrayList<>();
        for (List<JoinNode> joinOrder: joinOrders) {
            newTrees.add(JoinNode.reconstructJoinTreeFromTableNodes(joinOrder, JoinType.INNER));
        }
        //Collect all the join/where conditions to reassign them later
        AbstractExpression combinedWhereExpr = subTree.getAllFilters();
        List<JoinNode> treePermutations = new ArrayList<>();
        for (JoinNode newTree : newTrees) {
            if (combinedWhereExpr != null) {
                newTree.setWhereExpression(combinedWhereExpr.clone());
            }
            // The new tree root node id must match the original one to be able to reconnect the
            // subtrees
            newTree.setId(subTree.getId());
            treePermutations.add(newTree);
        }
        return treePermutations;
    }
732913
protected final void merge(final InternalNode<K, V> nodeParent, final int slot, final Node<K, V> nodeFROMx) {
		final LeafNode<K, V> nodeFROM = (LeafNode<K, V>) nodeFROMx;
		final LeafNode<K, V> nodeTO = this;
		final int sizeTO = nodeTO.allocated;
		final int sizeFROM = nodeFROM.allocated;
		// copy keys from nodeFROM to nodeTO
		System.arraycopy(nodeFROM.keys, 0, nodeTO.keys, sizeTO, sizeFROM);
		System.arraycopy(nodeFROM.values, 0, nodeTO.values, sizeTO, sizeFROM);
		nodeTO.allocated += sizeFROM;
		// remove key from nodeParent
		nodeParent.remove(slot);
		// Update Linked List (left) in new High
		if (nodeFROM.rightid != NULL_ID) {
			final LeafNode<K, V> rightFROM = (LeafNode<K, V>) tree.getNode(nodeFROM.rightid);
			rightFROM.leftid = id;
			tree.putNode(rightFROM);
		}
		// Update Linked List (right)
		rightid = nodeFROM.rightid;
		// update lowIdx on tree
		if (leftid == 0) {
			tree.lowIdx = id;
		}
		// update highIdx on tree
		if (rightid == 0) {
			tree.highIdx = id;
		}
		//
		// Free nodeFROM
		tree.freeNode(nodeFROM);
	}
489621
def unroot(self):
        
        if len(self.children)==2:
            if not self.children[0].is_leaf():
                self.children[0].delete()
            elif not self.children[1].is_leaf():
                self.children[1].delete()
            else:
                raise TreeError("Cannot unroot a tree with only two leaves")
297657
public void union(GeneralSubtrees other) {
        if (other != null) {
            for (int i = 0, n = other.size(); i < n; i++) {
                add(other.get(i));
            }
            // Minimize this
            minimize();
        }
    }
839878
def uproot(tree):
        
        uprooted = tree.copy()
        uprooted.parent = None
        for child in tree.all_children():
            uprooted.add_general_child(child)
        return uprooted
1255213
function mergeRecursive(obj1, obj2) {
  if (!obj1 && obj2) {
    obj1 = {};
  }
  for (var key in obj2) {
    if (!obj2.hasOwnProperty(key)) {
      continue;
    }
    merge(obj1, obj2, key);
  }
  return obj1;
}
1012288
public static JoinNode reconstructJoinTreeFromTableNodes(List<JoinNode> tableNodes, JoinType joinType) {
        JoinNode root = null;
        for (JoinNode leafNode : tableNodes) {
            JoinNode node = leafNode.cloneWithoutFilters();
            if (root == null) {
                root = node;
            } else {
                // We only care about the root node id to be able to reconnect the sub-trees
                // The intermediate node id can be anything. For the final root node its id
                // will be set later to the original tree's root id
                root = new BranchNode(-node.m_id, joinType, root, node);
            }
        }
        return root;
    }
863568
def join(cls, root, subkey):
        
        if subkey is None:
            return root
        return enums.SPLITTER.join((root, subkey))
697666
public static <T, R> TreeNode<R> copy(TreeDef<T> treeDef, T root, Function<? super T, ? extends R> mapper) {
		List<T> children = treeDef.childrenOf(root);
		R mapped = mapper.apply(root);
		TreeNode<R> copyRoot = new TreeNode<>(null, mapped, children.size());
		copyRecurse(copyRoot, treeDef, root, children, mapper);
		return copyRoot;
	}
925541
def get_tree_root(self):
        
        root = self
        while root.up is not None:
            root = root.up
        return root
152694
def clone_subtree start_node 
      new_tree = self.class.new
      list = [start_node] + start_node.descendents
      list.each do |x|
        new_tree.add_node(x)
      end
      each_edge do |node1, node2, edge|
        if new_tree.include?(node1) and new_tree.include?(node2) 
          new_tree.add_edge(node1, node2, edge)
        end
      end
      new_tree
    end
1298529
def add_child(self, tree):
        '''
        '''
        tree.parent = self
        self.children.append(tree)
        return tree
82807
def tree2bracket(docgraph, root=None, successors=None):
    
    if root is None:
        root = docgraph.root
    if successors is None:
        successors = sorted_bfs_successors(docgraph, root)

    if root in successors:
        embed_str = u" ".join(tree2bracket(docgraph, child, successors)
                              for child in successors[root])
        return node2bracket(docgraph, root, embed_str)
    return node2bracket(docgraph, root)