Inserts item x at position k, maintaining heap invariant by
demoting x down the tree repeatedly until it is less than or
equal to its children or is a leaf.

@param k the position to fill
@param x the item to insert
336711
private void siftDown(int k, E x) {
        if (comparator != null)
            siftDownUsingComparator(k, x);
        else
            siftDownComparable(k, x);
    }
117887
public void insert(INDArray point) {
        if (!point.isVector() || point.length() != dims)
            throw new IllegalArgumentException("Point must be a vector of length " + dims);

        if (root == null) {
            root = new KDNode(point);
            rect = new HyperRect(HyperRect.point(point));
        } else {
            int disc = 0;
            KDNode node = root;
            KDNode insert = new KDNode(point);
            int successor;
            while (true) {
                //exactly equal
                INDArray pt = node.getPoint();
                INDArray countEq = Nd4j.getExecutioner().execAndReturn(new Any(pt.neq(point))).z();
                if (countEq.getInt(0) == 0) {
                    return;
                } else {
                    successor = successor(node, point, disc);
                    KDNode child;
                    if (successor < 1)
                        child = node.getLeft();
                    else
                        child = node.getRight();
                    if (child == null)
                        break;
                    disc = (disc + 1) % dims;
                    node = child;
                }
            }

            if (successor < 1)
                node.setLeft(insert);

            else
                node.setRight(insert);

            rect.enlargeTo(point);
            insert.setParent(node);
        }
        size++;

    }
455620
public void insertSiblingAfter(Node node) {
    if (node != null) {
      node.setNextSibling(getNextSibling());
      node.setPrevSibling(this);
    }
  }
1052385
@Override
    @SuppressWarnings("unchecked")
    @ConstantTime(amortized = true)
    public AddressableHeap.Handle<K, V> insert(K key, V value) {
        if (other != this) {
            throw new IllegalStateException("A heap cannot be used after a meld");
        }
        if (key == null) {
            throw new NullPointerException("Null keys not permitted");
        }

        Node<K, V> n = new Node<K, V>(this, key, value);
        if (root == null) {
            root = n;
        } else {
            if (comparator == null) {
                if (((Comparable<? super K>) n.key).compareTo(root.key) < 0) {
                    root = link(root, n);
                } else {
                    link(n, root);
                }
            } else {
                if (comparator.compare(n.key, root.key) < 0) {
                    root = link(root, n);
                } else {
                    link(n, root);
                }
            }
        }
        size++;
        return n;
    }
963107
Node insertChildAt(Node newChild, int index) throws DOMException {
        if (newChild instanceof DocumentFragment) {
            NodeList toAdd = newChild.getChildNodes();
            for (int i = 0; i < toAdd.getLength(); i++) {
                insertChildAt(toAdd.item(i), index + i);
            }
            return newChild;
        }

        LeafNodeImpl toInsert = (LeafNodeImpl) newChild;
        if (toInsert.document != null && document != null && toInsert.document != document) {
            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
        }
        if (toInsert.isParentOf(this)) {
            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
        }

        if (toInsert.parent != null) {
            int oldIndex = toInsert.index;
            toInsert.parent.children.remove(oldIndex);
            toInsert.parent.refreshIndices(oldIndex);
        }

        children.add(index, toInsert);
        toInsert.parent = this;
        refreshIndices(index);

        return newChild;
    }
227386
def insert(key, value)
      node = myself

      # Traverse the tree to find the right node to add or replace the value.
      while node do
        # All nodes that we find on the way that are full will be split into
        # two half-full nodes.
        if node.keys.size >= @tree.node_size
          node = node.split_node
        end

        # Once we have reached a leaf node we can insert or replace the value.
        if node.is_leaf?
          return node.insert_element(key, value)
        else
          # Descend into the right child node to add the value to.
          node = node.children[node.search_key_index(key)]
        end
      end

      PEROBS.log.fatal "Could not find proper node to insert into"
    end
135007
public void add(double[] x) {
        if (root == null) {
            root = new Node();
            root.add(new Leaf(x));
            root.update(x);
        } else {
            root.add(x);
        }
    }
1130775
@Override
    @LogarithmicTime(amortized = true)
    public AddressableHeap.Handle<K, V> insert(K key, V value) {
        if (other != this) {
            throw new IllegalStateException("A heap cannot be used after a meld");
        }
        if (key == null) {
            throw new NullPointerException("Null keys not permitted");
        }
        Node<K, V> n = new Node<K, V>(this, key, value);
        if (comparator == null) {
            root = link(root, n);
        } else {
            root = linkWithComparator(root, n);
        }
        size++;
        return n;
    }
259901
public void insertParentAfter(Node node) throws ChildNodeException {
    if (node != null) {
      // give this node my children
      node.setFirstChild(getFirstChild());

      setFirstChild(null); // clear our list
      addChild(node);      // make our child
    }
  }
987518
final TreeNode<K,V> putTreeVal(int h, K k, V v) {
            Class<?> kc = null;
            boolean searched = false;
            for (TreeNode<K,V> p = root;;) {
                int dir, ph; K pk;
                if (p == null) {
                    first = root = new TreeNode<K,V>(h, k, v, null, null);
                    break;
                }
                else if ((ph = p.hash) > h)
                    dir = -1;
                else if (ph < h)
                    dir = 1;
                else if ((pk = p.key) == k || (pk != null && k.equals(pk)))
                    return p;
                else if ((kc == null &&
                          (kc = comparableClassFor(k)) == null) ||
                         (dir = compareComparables(kc, k, pk)) == 0) {
                    if (!searched) {
                        TreeNode<K,V> q, ch;
                        searched = true;
                        if (((ch = p.left) != null &&
                             (q = ch.findTreeNode(h, k, kc)) != null) ||
                            ((ch = p.right) != null &&
                             (q = ch.findTreeNode(h, k, kc)) != null))
                            return q;
                    }
                    dir = tieBreakOrder(k, pk);
                }

                TreeNode<K,V> xp = p;
                if ((p = (dir <= 0) ? p.left : p.right) == null) {
                    TreeNode<K,V> x, f = first;
                    first = x = new TreeNode<K,V>(h, k, v, f, xp);
                    if (f != null)
                        f.prev = x;
                    if (dir <= 0)
                        xp.left = x;
                    else
                        xp.right = x;
                    if (!xp.red)
                        x.red = true;
                    else {
                        lockRoot();
                        try {
                            root = balanceInsertion(root, x);
                        } finally {
                            unlockRoot();
                        }
                    }
                    break;
                }
            }
            assert checkInvariants(root);
            return null;
        }
1368828
public Tree<K, V> lookup(Tree<K, V> tree, K x) {
        if (tree == null)
            return null;

        int cmp = ordering.compare(x, tree.getKey(kf));

        if (cmp < 0) return lookup(tree.getLeft(), x);
        else if (cmp > 0) return lookup(tree.getRight(), x);
        else return tree;
    }
551748
public synchronized void remove(String k) {
        if(k == null) {
            for (int i = 0; i < nkeys; i++) {
                while (keys[i] == null && i < nkeys) {
                    for(int j=i; j<nkeys-1; j++) {
                        keys[j] = keys[j+1];
                        values[j] = values[j+1];
                    }
                    nkeys--;
                }
            }
        } else {
            for (int i = 0; i < nkeys; i++) {
                while (k.equalsIgnoreCase(keys[i]) && i < nkeys) {
                    for(int j=i; j<nkeys-1; j++) {
                        keys[j] = keys[j+1];
                        values[j] = values[j+1];
                    }
                    nkeys--;
                }
            }
        }
    }
642004
public void put(ElementType x) {
        if (full()) {
            getIdx = (getIdx + 1) % elements.length;
        } else {
            size++;
        }

        elements[putIdx] = x;
        putIdx = (putIdx + 1) % elements.length;
    }
434230
private void link(Node<K, V> y, Node<K, V> x) {
        // remove from root list
        y.prev.next = y.next;
        y.next.prev = y.prev;

        // one less root
        roots--;

        // clear if marked
        y.mark = false;

        // hang as x's child
        x.degree++;
        y.parent = x;

        Node<K, V> child = x.child;
        if (child == null) {
            x.child = y;
            y.next = y;
            y.prev = y;
        } else {
            y.prev = child;
            y.next = child.next;
            child.next = y;
            y.next.prev = y;
        }
    }
1318353
private void cut(Node<K, V> x, Node<K, V> y) {
        // remove x from child list of y
        x.prev.next = x.next;
        x.next.prev = x.prev;
        y.degree--;
        if (y.degree == 0) {
            y.child = null;
        } else if (y.child == x) {
            y.child = x.next;
        }

        // add x to the root list
        x.parent = null;
        addToRootList(x);

        // clear if marked
        x.mark = false;
    }
940725
@SuppressWarnings("unchecked")
    void insert(Suffix<T, S> suffix, ActivePoint<T, S> activePoint) {
        Object item = suffix.getEndItem();

        if (edges.containsKey(item)) {
            if (tree.isNotFirstInsert() && activePoint.getNode() != tree.getRoot())
                tree.setSuffixLink(activePoint.getNode());
            activePoint.setEdge(edges.get(item));
            activePoint.incrementLength();
        } else {
            saveSequenceTerminal(item);
            Edge<T, S> newEdge = new Edge<>(suffix.getEndPosition() - 1, this,
                    sequence, tree);
            edges.put((T) suffix.getEndItem(), newEdge);
            suffix.decrement();
            activePoint.updateAfterInsert(suffix);

            if (tree.isNotFirstInsert() && !this.equals(tree.getRoot())) {
                tree.getLastNodeInserted().setSuffixLink(this);
            }
            if (suffix.isEmpty()) {
            }
            else
                tree.insert(suffix);
        }
    }
302124
private void insert(String key, RadixTreeNode<T> node, T value)
            throws DuplicateKeyException {

        int numberOfMatchingCharacters = node.getNumberOfMatchingCharacters(key);

        // we are either at the root node
        // or we need to go down the tree
        if (node.getKey().equals("") == true || numberOfMatchingCharacters == 0 || (numberOfMatchingCharacters < key.length() && numberOfMatchingCharacters >= node.getKey().length())) {
            boolean flag = false;
            String newText = key.substring(numberOfMatchingCharacters, key.length());
            for (RadixTreeNode<T> child : node.getChildern()) {
                if (child.getKey().startsWith(newText.charAt(0) + "")) {
                    flag = true;
                    insert(newText, child, value);
                    break;
                }
            }

            // just add the node as the child of the current node
            if (flag == false) {
                RadixTreeNode<T> n = new RadixTreeNode<T>();
                n.setKey(newText);
                n.setReal(true);
                n.setValue(value);

                node.getChildern().add(n);
            }
        }
        // there is a exact match just make the current node as data node
        else if (numberOfMatchingCharacters == key.length() && numberOfMatchingCharacters == node.getKey().length()) {
            if (node.isReal() == true) {
                throw new DuplicateKeyException("Duplicate key");
            }

            node.setReal(true);
            node.setValue(value);
        }
        // This node need to be split as the key to be inserted
        // is a prefix of the current node key
        else if (numberOfMatchingCharacters > 0 && numberOfMatchingCharacters < node.getKey().length()) {
            RadixTreeNode<T> n1 = new RadixTreeNode<T>();
            n1.setKey(node.getKey().substring(numberOfMatchingCharacters, node.getKey().length()));
            n1.setReal(node.isReal());
            n1.setValue(node.getValue());
            n1.setChildern(node.getChildern());

            node.setKey(key.substring(0, numberOfMatchingCharacters));
            node.setReal(false);
            node.setChildern(new ArrayList<RadixTreeNode<T>>());
            node.getChildern().add(n1);
            
            if(numberOfMatchingCharacters < key.length()) {
	            RadixTreeNode<T> n2 = new RadixTreeNode<T>();
	            n2.setKey(key.substring(numberOfMatchingCharacters, key.length()));
	            n2.setReal(true);
	            n2.setValue(value);
	            
	            node.getChildern().add(n2);
            } else {
            	node.setValue(value);
                node.setReal(true);
            }
        }        
        // this key need to be added as the child of the current node
        else {
            RadixTreeNode<T> n = new RadixTreeNode<T>();
            n.setKey(node.getKey().substring(numberOfMatchingCharacters, node.getKey().length()));
            n.setChildern(node.getChildern());
            n.setReal(node.isReal());
            n.setValue(node.getValue());

            node.setKey(key);
            node.setReal(true);
            node.setValue(value);

            node.getChildern().add(n);
        }
    }