Appends two trees.
191845
function append(a,b)
{
	if (a.table.length === 0)
	{
		return b;
	}
	if (b.table.length === 0)
	{
		return a;
	}

	var c = append_(a, b);

	// Check if both nodes can be crunshed together.
	if (c[0].table.length + c[1].table.length <= M)
	{
		if (c[0].table.length === 0)
		{
			return c[1];
		}
		if (c[1].table.length === 0)
		{
			return c[0];
		}

		// Adjust .table and .lengths
		c[0].table = c[0].table.concat(c[1].table);
		if (c[0].height > 0)
		{
			var len = length(c[0]);
			for (var i = 0; i < c[1].lengths.length; i++)
			{
				c[1].lengths[i] += len;
			}
			c[0].lengths = c[0].lengths.concat(c[1].lengths);
		}

		return c[0];
	}

	if (c[0].height > 0)
	{
		var toRemove = calcToRemove(a, b);
		if (toRemove > E)
		{
			c = shuffle(c[0], c[1], toRemove);
		}
	}

	return siblise(c[0], c[1]);
}
92052
public void addEdge(N a, N b)
    {
        if( !containsBoth(a, b) )
            return;//Cant add nodes to things that doing exist
        nodes.get(a).getOutgoing().add(b);
        nodes.get(b).getIncoming().add(a);
    }
921690
def put(self, key, value, append=False):
        
        self._put(ConfigTree.parse_key(key), value, append)
455093
public Tree<T> addSubtree( Tree<T> subtree )
    {
        Tree<T> copy = addLeaf( subtree.data );
        copy.children = new ArrayList<Tree<T>>( subtree.children );
        return copy;
    }
1014135
private void condenseTree(IndexTreePath<E> subtree, Stack<N> stack) {
    N node = getNode(subtree.getEntry());
    // node is not root
    if(!isRoot(node)) {
      N parent = getNode(subtree.getParentPath().getEntry());
      int index = subtree.getIndex();
      if(hasUnderflow(node)) {
        if(parent.deleteEntry(index)) {
          stack.push(node);
        }
        else {
          node.adjustEntry(parent.getEntry(index));
        }
      }
      else {
        node.adjustEntry(parent.getEntry(index));
      }
      writeNode(parent);
      // get subtree to parent
      condenseTree(subtree.getParentPath(), stack);
    }

    // node is root
    else {
      if(hasUnderflow(node) && node.getNumEntries() == 1 && !node.isLeaf()) {
        N child = getNode(node.getEntry(0));
        final N newRoot;
        if(child.isLeaf()) {
          newRoot = createNewLeafNode();
          newRoot.setPageID(getRootID());
          for(int i = 0; i < child.getNumEntries(); i++) {
            newRoot.addLeafEntry(child.getEntry(i));
          }
        }
        else {
          newRoot = createNewDirectoryNode();
          newRoot.setPageID(getRootID());
          for(int i = 0; i < child.getNumEntries(); i++) {
            newRoot.addDirectoryEntry(child.getEntry(i));
          }
        }
        writeNode(newRoot);
        height--;
      }
    }
  }
98614
function createTree(){
    for (var i = 0; i < gRootNodes.length; ++i){
        var node = {
            _id : gRootNodes[i]._id, //todo : id instead of name?
            node : gRootNodes[i],
            parent : "root",
            childNodes : loadChildNodes(gRootNodes[i])
        };
        gTree.childNodes.push(node);
    }
}
586050
private void merge(FieldNumberTree other) {
    for (Key key : other.children.keySet()) {
      FieldNumberTree value = other.children.get(key);
      if (!this.children.containsKey(key)) {
        this.children.put(key, value);
      } else {
        this.children.get(key).merge(value);
      }
    }
  }
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
551095
def push(self, x):
        """"""
        assert x not in self.rank
        i = len(self.heap)
        self.heap.append(x)    # add a new leaf
        self.rank[x] = i
        self.up(i)
1361808
def append_string(t, string):
    """"""
    node = t.tree
    if string:
        if len(node) == 0:
            if node.text is not None:
                node.text += string
            else:
                node.text = string
        else:  # Get last child
            child = list(node)[-1]
            if child.tail is not None:
                child.tail += string
            else:
                child.tail = string
83078
def Append(self, component=None, **kwarg):
    """"""
    if component is None:
      component = self.__class__(**kwarg)

    if self.HasField("pathtype"):
      self.last.nested_path = component
    else:
      for k, v in iteritems(kwarg):
        setattr(self, k, v)

      self.SetRawData(component.GetRawData())

    return self
615953
public AbstractNode combine(AbstractNode midd1, AbstractNode midd2) throws MIDDException {

        if (midd1 instanceof ExternalNode3) {
            if (midd2 instanceof ExternalNode3) {
                return combineExternalNodes((ExternalNode3) midd1, (ExternalNode3) midd2);            // combine two external nodes
            } else {
                ExternalNode3 n1 = (ExternalNode3) midd1;
                InternalNode<?> n2 = (InternalNode<?>) midd2;
                return combineIDD(n1, n2); // combine an external node n1 with an internal node n2
            }
        } else {
            InternalNode<?> n1 = (InternalNode<?>) midd1;

            if (midd2 instanceof ExternalNode3) {
                // combine an internal node (midd1) with an external node (midd2)
                ExternalNode3 n2 = (ExternalNode3) midd2;
                return combineIDD(n1, n2);     // combine an internal node n1 with an external node2
            } else {
                // both are internal nodes, combine two internal nodes here
                InternalNode<?> n2 = (InternalNode<?>) midd2;

                if (n1.getID() == n2.getID()) {
                    return combineIDDSameLevel(n1, n2);
                } else {
                    //Algorithm: find a node with lower order, e.g: n1
                    // - Create a node clone from n1 -> n
                    // - combine n2 with all children of n1 -> children[1..k], add them to children of n

                    InternalNode<?> n = null;
                    if (n1.getID() < n2.getID()) {

                        // Clone n1
                        n = NodeUtils.createInternalNode(n1, n1.getType());

                        for (AbstractEdge<?> e : n1.getEdges()) {
                            AbstractNode child = combine(e.getSubDiagram(), n2);
                            if (child != null) {
                                n.addChild(EdgeUtils.cloneEdge(e), child);
                            } else {
                                log.error("empty child");
                            }
                        }

                        // Create a new edge containing the complement of n1 children intervals, connecting n with n2
                        List<Interval<?>> complementIntervals = IntervalUtils.complement(n1.getIntervals());
                        if (complementIntervals.size() > 0) {
                            AbstractEdge<?> edge = EdgeUtils.createEdge(complementIntervals, n1.getType());
                            n.addChild(edge, n2);
                        }

                    } else { // n2 has lower id than n1, do in other way.
                        n = NodeUtils.createInternalNode(n2, n2.getType());
                        for (AbstractEdge<?> e : n2.getEdges()) {
                            AbstractNode child = combine(n1, e.getSubDiagram());
                            if (child != null) {
                                n.addChild(EdgeUtils.cloneEdge(e), child);
                            }
                        }
                        // Create a new edge containing the complement of n2 children intervals, connecting n with n1
                        List<Interval<?>> complementIntervals = IntervalUtils.complement(n2.getIntervals());
                        if (complementIntervals.size() > 0) {
                            AbstractEdge<?> edge = EdgeUtils.createEdge(complementIntervals, n2.getType());
                            n.addChild(edge, n1);
                        }
                    }
                    if (n.getEdges().size() > 0) {
                        return n;
                    } else {
                        return null;
                    }
                }
            }
        }
    }
691616
def insert(self, key):
        
        # Create new node
        n = TreeNode(key)
        if not self.node:
            self.node = n
            self.node.left = AvlTree()
            self.node.right = AvlTree()
        elif key < self.node.val:
            self.node.left.insert(key)
        elif key > self.node.val:
            self.node.right.insert(key)
        self.re_balance()
609463
function concat(a, b) {
	var aLen = a.size;
	var bLen = b.size;
	var newLen = aLen + bLen;

	if (aLen === 0) return b;
	if (bLen === 0) return a;

	if (!a.root || !b.root) {
		if (aLen + bLen <= _const.M) {
			let newTail = a.tail.concat(b.tail);
			newTail.height = 0;
			if (!a.editable) return new Tree(newLen, null, newTail);
			a.size = newLen;
			a.root = null;
			a.tail = newTail;
			return a;
		}
		if (!a.root && !b.root) {
			// newTail will overflow, but newRoot can't be over M
			let newRoot = a.tail.concat(b.tail.slice(0, _const.M - aLen));
			newRoot.height = 0;
			let newTail = b.tail.slice(_const.M - aLen);
			newTail.height = 0;
			if (!a.editable) return new Tree(newLen, newRoot, newTail);
			a.size = newLen;
			a.root = newRoot;
			a.tail = newTail;
			return a;
		}
		// else either a has a root or b does
		if (!b.root) {
			// b has no root
			let aTailLen = a.tail.length;
			let bTailLen = b.tail.length;
			// size left over in last root node in a
			let rightCut = _const.M - aTailLen;
			// create a new tail by concatting b until cut
			let newTail = a.tail.concat(b.tail.slice(0, rightCut));
			newTail.height = 0;
			let newRoot;
			// if tail would overflow, sink it and make leftover newTail
			if (aTailLen + bTailLen > _const.M) {
				newRoot = (0, _util.sinkTailIfSpace)(newTail, a.root, a.editable);
				newTail = b.tail.slice(rightCut);
				newTail.height = 0;
			} else {
				newRoot = a.root.slice(0);
				if(a.root.height) newRoot.sizes = a.root.sizes.slice(0);
				newRoot.height = a.root.height;
			}
			if (!a.editable) return new Tree(newLen, newRoot, newTail);
			a.size = newLen;
			a.root = newRoot;
			a.tail = newTail;
			return a;
		}
		// else a has no root
		// make a.tail a.root and concat b.root
		let newRoot = (0, _concat.concatRoot)((0, _util.parentise)(a.tail, 1), b.root, a.editable);
		let newTail = (0, _util.createLeafFrom)(b.tail, a.editable);
		if (!a.editable) return new Tree(newLen, newRoot, newTail);
		a.size = newLen;
		a.root = newRoot;
		a.tail = newTail;
		return a;
	} else {
		// both a and b have roots
		// if have a.tail, just sink a.tail and make b.tail new tail...
		let aRoot = a.tail.length === 0 ? a.root : (0, _util.sinkTailIfSpace)(a.tail, a.root, a.editable) || (0, _util.siblise)(a.root, (0, _util.parentise)(a.tail, a.root.height));
		let newRoot = (0, _concat.concatRoot)(aRoot, b.root, a.editable);
		let newTail = (0, _util.createLeafFrom)(b.tail, a.editable);
		if (!a.editable) return new Tree(newLen, newRoot, newTail);
		a.size = newLen;
		a.root = newRoot;
		a.tail = newTail;
		return a;
	}
}
230265
def add_child(self, **kwargs):
        """"""
        if not self.is_leaf():
            # there are child nodes, delegate insertion to add_sibling
            if self.node_order_by:
                pos = 'sorted-sibling'
            else:
                pos = 'last-sibling'
            last_child = self.get_last_child()
            last_child._cached_parent_obj = self
            return last_child.add_sibling(pos, **kwargs)

        # we're adding the first child of this node
        sql, params = self.__class__._move_right(self.tree_id,
                                                 self.rgt, False, 2)

        if len(kwargs) == 1 and 'instance' in kwargs:
            # adding the passed (unsaved) instance to the tree
            newobj = kwargs['instance']
            if newobj.pk:
                raise NodeAlreadySaved("Attempted to add a tree node that is "\
                    "already in the database")
        else:
            # creating a new object
            newobj = get_result_class(self.__class__)(**kwargs)

        newobj.tree_id = self.tree_id
        newobj.depth = self.depth + 1
        newobj.lft = self.lft + 1
        newobj.rgt = self.lft + 2

        # this is just to update the cache
        self.rgt += 2

        newobj._cached_parent_obj = self

        cursor = self._get_database_cursor('write')
        cursor.execute(sql, params)

        # saving the instance before returning it
        newobj.save()

        return newobj
1215829
void appendStrings(JCTree tree) {
            tree = TreeInfo.skipParens(tree);
            if (tree.hasTag(PLUS) && tree.type.constValue() == null) {
                JCBinary op = (JCBinary) tree;
                if (op.operator.kind == MTH &&
                    ((OperatorSymbol) op.operator).opcode == string_add) {
                    appendStrings(op.lhs);
                    appendStrings(op.rhs);
                    return;
                }
            }
            genExpr(tree, tree.type).load();
            appendString(tree);
        }
259190
def add_to_pairtree(output_path, meta_id):
    """"""
    # create the pair path
    paired_path = pair_tree_creator(meta_id)
    path_append = ''
    # for each directory in the pair path
    for pair_dir in paired_path.split(os.sep):
        # append the pair path together, one directory at a time
        path_append = os.path.join(path_append, pair_dir)
        # append the pair path to the output path
        combined_path = os.path.join(output_path, path_append)
        # if the path doesn't already exist, create it
        if not os.path.exists(combined_path):
            os.mkdir(combined_path)
    return combined_path