Re balance tree. After inserting or deleting a node,
5543
def re_balance(self):
        
        self.update_heights(recursive=False)
        self.update_balances(False)

        while self.balance < -1 or self.balance > 1:
            if self.balance > 1:
                if self.node.left.balance < 0:
                    self.node.left.rotate_left()
                    self.update_heights()
                    self.update_balances()
                self.rotate_right()
                self.update_heights()
                self.update_balances()

            if self.balance < -1:
                if self.node.right.balance > 0:
                    self.node.right.rotate_right()
                    self.update_heights()
                    self.update_balances()
                self.rotate_left()
                self.update_heights()
                self.update_balances()
651921
def replace_nodes(root, old, new):

    '''
     
    '''

    rep = Replacer(old, new)
    rep.visit(root)
    return
663796
def delete_node(self, loadbalancer, node):
        """"""
        lb = node.parent
        if not lb:
            raise exc.UnattachedNode("No parent Load Balancer for this node "
                    "could be determined.")
        resp, body = self.api.method_delete("/loadbalancers/%s/nodes/%s" %
                (lb.id, node.id))
        return resp, body
35302
void balancedPush(
    int         state,
    GBSNode     node)
  {
    push(state, node);
    if (node.balance() != 0)
      _bpidx = _cidx;
  }
578028
private Entry insertHereWithSplit(Entry toInsert, Node insertNode,
			long timestamp) {
		//Handle root split
   	    if (insertNode.getEntries()[0].getParentEntry()==null){
   	    	root.makeOlder(timestamp, negLambda);
   	    	Entry irrelevantEntry = insertNode.getIrrelevantEntry(this.weightThreshold);
   	        int numFreeEntries = insertNode.numFreeEntries();
   	        if (irrelevantEntry != null) {
   		        irrelevantEntry.overwriteOldEntry(toInsert);
   	        }
   	        else if (numFreeEntries>0){
   	        	insertNode.addEntry(toInsert, timestamp);
   	        }
   	        else{
	            this.numRootSplits++;
	            this.height += this.height < this.maxHeight ? 1 : 0;
	            Entry oldRootEntry = new Entry(this.numberDimensions,
	                    root, timestamp, null, null);
	            Node newRoot = new Node(this.numberDimensions,
	                    this.height);
	            Entry newRootEntry = split(toInsert, root, oldRootEntry, timestamp);
	            newRoot.addEntry(oldRootEntry, timestamp);
	            newRoot.addEntry(newRootEntry, timestamp);
	            this.root = newRoot;
	            for (Entry c : oldRootEntry.getChild().getEntries())
	            	c.setParentEntry(root.getEntries()[0]);
	            for (Entry c : newRootEntry.getChild().getEntries())
	            	c.setParentEntry(root.getEntries()[1]);
   	        }
            return null;
   	    }
   	    insertNode.makeOlder(timestamp, negLambda);
    	Entry irrelevantEntry = insertNode.getIrrelevantEntry(this.weightThreshold);
        int numFreeEntries = insertNode.numFreeEntries();
        if (irrelevantEntry != null) {
	        irrelevantEntry.overwriteOldEntry(toInsert);
        }
        else if (numFreeEntries>0){
        	insertNode.addEntry(toInsert, timestamp);
        }
        else {
	            // We have to split.
	        	Entry parentEntry = insertNode.getEntries()[0].getParentEntry();
	        	Entry residualEntry = split(toInsert, insertNode, parentEntry, timestamp);
	        	if (alsoUpdate!=null){
	        		alsoUpdate = residualEntry;
	        	}
	        	Node nodeForResidualEntry = insertNode.getEntries()[0].getParentEntry().getNode();
	        	//recursive call
	        	return insertHereWithSplit(residualEntry, nodeForResidualEntry, timestamp);
	    }
        
        //no Split
        return null;
	}
358968
private void deleteCheckFringeBalance(
                                         DeleteStack   stack,
                                         GBSNode       endp,
                                         int           endIndex,
                                         int           maxBal)
    {

        int           fDepth = 0;      /* Fringe balance depth                  */

        fDepth = 0;
        if (endp.leftChild() == null)
        {
            fDepth = 1;                /* Last node counts as one               */
            for (int j = endIndex; j > 0; j--)
            {
                GBSNode q = stack.node(j);
                if (q.leftChild() == null)/* Have not found end yet               */
                    fDepth++;
                else                     /* Found the top of the fringe           */
                    break;
            }
        }

        int t0_depth = tZeroDepth();
        int t = t0_depth;
        if (t < 1)
            t = 1;

        if ( (stack.maxDepth() >= t) &&/* Deep enough for a t0 and              */
             (endp.population() == (endp.width()-1))  )/* Last node was full   */
        {
            /* Check for a possible t0 tree          */
            int j = 1;
            if ((kFactor() % 3) == 0)
                j = 2;
            if (fDepth == j)
            {
                _xno++;
                GBSDeleteFringe.singleInstance().balance(
                                                        tZeroDepth(), stack);
            }
        }
        else                          /* Not a t0 fringe                       */
        {
            /* Check for empty node                  */
            if (endp.population() != 0)
                endp.adjustMedian();
            else
            {
                _xno++;
                GBSNode p = stack.node(endIndex);
                if (p.leftChild() == endp)
                    p.setLeftChild(null);
                else
                    p.setRightChild(null);
            }
        }
    }
1235143
public void replaceNode(final ADTNode<S, I, O> oldNode, final ADTNode<S, I, O> newNode) {

        if (this.root.equals(oldNode)) {
            this.root = newNode;
        } else if (ADTUtil.isResetNode(oldNode)) {
            final ADTNode<S, I, O> endOfPreviousADS = oldNode.getParent();
            final O outputToReset = ADTUtil.getOutputForSuccessor(endOfPreviousADS, oldNode);

            newNode.setParent(endOfPreviousADS);
            endOfPreviousADS.getChildren().put(outputToReset, newNode);
        } else {
            final ADTNode<S, I, O> oldNodeParent = oldNode.getParent(); //reset node

            assert ADTUtil.isResetNode(oldNodeParent);

            final ADTNode<S, I, O> endOfPreviousADS = oldNodeParent.getParent();
            final O outputToReset = ADTUtil.getOutputForSuccessor(endOfPreviousADS, oldNodeParent);
            final ADTNode<S, I, O> newResetNode = new ADTResetNode<>(newNode);

            newResetNode.setParent(endOfPreviousADS);
            newNode.setParent(newResetNode);
            endOfPreviousADS.getChildren().put(outputToReset, newResetNode);
        }
    }
234426
function clear (node) {
    const replace = node.cloneNode(false);
    node.parentNode.replaceChild(replace, node);
    return replace;
  }
1318135
function replaceWithMultiple(nodes) {
  this.resync();

  nodes = this._verifyNodeList(nodes);
  t.inheritLeadingComments(nodes[0], this.node);
  t.inheritTrailingComments(nodes[nodes.length - 1], this.node);
  this.node = this.container[this.key] = null;
  this.insertAfter(nodes);
  if (!this.node) this.dangerouslyRemove();
}
556513
public void reset() {
		Enumeration<TreeNode> children = root.children();
		while (children.hasMoreElements()) {
			removeNodeFromParent((MutableTreeNode) children.nextElement());
			children = root.children();
		}
	}
631705
function insertTo(root, node, before) {
  if (!root) return
  root.insertBefore(before, node)
  root.removeChild(node)
}
68662
private boolean rebalance(final NodeInterval newNode) {

        NodeInterval prevRebalanced = null;
        NodeInterval curChild = leftChild;
        List<NodeInterval> toBeRebalanced = Lists.newLinkedList();
        do {
            if (curChild.isItemOverlap(newNode)) {
                toBeRebalanced.add(curChild);
            } else {
                if (toBeRebalanced.size() > 0) {
                    break;
                }
                prevRebalanced = curChild;
            }
            curChild = curChild.rightSibling;
        } while (curChild != null);

        if (toBeRebalanced.isEmpty()) {
            return false;
        }

        newNode.parent = this;
        final NodeInterval lastNodeToRebalance = toBeRebalanced.get(toBeRebalanced.size() - 1);
        newNode.rightSibling = lastNodeToRebalance.rightSibling;
        lastNodeToRebalance.rightSibling = null;
        if (prevRebalanced == null) {
            leftChild = newNode;
        } else {
            prevRebalanced.rightSibling = newNode;
        }

        NodeInterval prev = null;
        for (NodeInterval cur : toBeRebalanced) {
            cur.parent = newNode;
            if (prev == null) {
                newNode.leftChild = cur;
            } else {
                prev.rightSibling = cur;
            }
            prev = cur;
        }
        return true;
    }
69393
public void reInsert(N node, IndexTreePath<E> path, int[] offs) {
    final int depth = path.getPathCount();

    long[] remove = BitsUtil.zero(node.getCapacity());
    List<E> reInsertEntries = new ArrayList<>(offs.length);
    for(int i = 0; i < offs.length; i++) {
      reInsertEntries.add(node.getEntry(offs[i]));
      BitsUtil.setI(remove, offs[i]);
    }
    // Remove the entries we reinsert
    node.removeMask(remove);
    writeNode(node);

    // and adapt the mbrs
    IndexTreePath<E> childPath = path;
    N child = node;
    while(childPath.getParentPath() != null) {
      N parent = getNode(childPath.getParentPath().getEntry());
      int indexOfChild = childPath.getIndex();
      if(child.adjustEntry(parent.getEntry(indexOfChild))) {
        writeNode(parent);
        childPath = childPath.getParentPath();
        child = parent;
      }
      else {
        break;
        // TODO: stop writing when MBR didn't change!
      }
    }

    // reinsert the first entries
    final Logging log = getLogger();
    for(E entry : reInsertEntries) {
      if(node.isLeaf()) {
        if(log.isDebugging()) {
          log.debug("reinsert " + entry);
        }
        insertLeafEntry(entry);
      }
      else {
        if(log.isDebugging()) {
          log.debug("reinsert " + entry + " at " + depth);
        }
        insertDirectoryEntry(entry, depth);
      }
    }
  }
1178539
def update_node(self, node, diff=None):
        """"""
        lb = node.parent
        if not lb:
            raise exc.UnattachedNode("No parent Load Balancer for this node "
                    "could be determined.")
        if diff is None:
            diff = node._diff()
        req_body = {"node": diff}
        resp, body = self.api.method_put("/loadbalancers/%s/nodes/%s" %
                (lb.id, node.id), body=req_body)
        return resp, body
828614
void reindex(Session session, Index index) {

        setAccessor(index, null);

        RowIterator it = table.rowIterator(session);

        while (it.hasNext()) {
            Row row = it.getNextRow();

            // may need to clear the node before insert
            index.insert(session, this, row);
        }
    }
65677
function(node) {
        this.logger.log("insertAfter: " + node);
        var p = node.parent;
        if (p) {

            if (this.tree) {
                this.tree.popNode(this);
            }

            var refIndex = node.isChildOf(p);
            this.logger.log(refIndex);

            if (!node.nextSibling) {
                this.nextSibling = null;
                return this.appendTo(p);
            }

            p.children.splice(refIndex + 1, 0, this);

            node.nextSibling.previousSibling = this;
            this.previousSibling = node;
            this.nextSibling = node.nextSibling;
            node.nextSibling = this;

            this.applyParent(p);
        }

        return this;
    }
683510
function(newNode, refNode){
      var nodes = this.nodes;
      var pos = refNode ? nodes.indexOf(refNode) : -1;

      if (pos == -1)
      {
        nodes.push(newNode);
        this.last = newNode;
      }
      else
        nodes.splice(pos, 0, newNode);

      this.first = nodes[0];

      newNode.groupNode = this;

      this.emit_childNodesModified({ inserted: [newNode] });
    }