Method reBalance.

@param xx HeightNote
@param bparent Parent of the balance point
@param bpoint The balance point
@param bnext Next child below balance point
160621
private void reBalance(
    DeleteStack.HeightNote   xx,
    GBSNode                  bparent,
    GBSNode                  bpoint,
    GBSNode                  bnext)
  {
    xx.bnew = bpoint;              /* Default for next time                 */
    if (bpoint.leftChild() == bnext)/* We deleted from left side            */
      {                            /* Check for RR or RL Rotation           */
        switch (bpoint.balance())  /* Look at ORIGINAL Balance Factor       */
        {
          case 0:                  /* Have deleted a left node of a balanced*/
            bpoint.setBalance(1);  /*  tree.  Now right heavy.              */
            break;
          case 1:                  /* Deleted left node of right heavy      */
            rotateRight(xx, bparent, bpoint);/* Need to re-balance          */
            break;
          case -1:                 /* Deleted left node of left-heavy tree  */
            bpoint.clearBalance(); /* It becomes balanced & depth decreases */
            xx.depthDecrease = true;
            break;
          default:
            throw new RuntimeException("bpoint.balance() = " + bpoint.balance());
        }
      }
    else                           /* We deleted from right side            */
      {                            /* Check for LL or LR Rotation           */
        switch (bpoint.balance())  /* Look at ORIGINAL Balance Factor       */
        {
          case 0:                  /* Deleted a right node of a balanced    */
            bpoint.setBalance(-1); /*  tree.  Now left-heavy                */
            break;
          case -1:                 /* Deleted right node of left-heavy      */
            rotateLeft(xx, bparent, bpoint);/* Need to re-balance           */
            break;
          case 1:                  /* Deleted a right node of a right-heavy */
            bpoint.clearBalance(); /* It become balanced & depth decreases  */
            xx.depthDecrease = true;
            break;
          default:
            throw new RuntimeException("bpoint.balance() = " + bpoint.balance());
        }
      }
  }
324624
function processTopLevelNode (node, expectedIndent) {
    const token = tokenStore.getFirstToken(node)
    const offsetInfo = offsets.get(token)
    if (offsetInfo != null) {
      offsetInfo.expectedIndent = expectedIndent
    } else {
      offsets.set(token, { baseToken: null, offset: 0, baseline: false, expectedIndent })
    }
  }
395629
public synchronized void releaseRebalancingPermit(int nodeId) {
        boolean removed = rebalancePermits.remove(nodeId);
        logger.info("Releasing rebalancing permit for node id " + nodeId + ", returned: " + removed);
        if(!removed)
            throw new VoldemortException(new IllegalStateException("Invalid state, must hold a "
                                                                   + "permit to release"));
    }
426986
public static void sort(BaseComponent parent, boolean recurse) {
        if (parent == null || parent.getChildren().size() < 2) {
            return;
        }

        int i = 1;
        int size = parent.getChildren().size();

        while (i < size) {
            Treenode item1 = (Treenode) parent.getChildren().get(i - 1);
            Treenode item2 = (Treenode) parent.getChildren().get(i);

            if (compare(item1, item2) > 0) {
                parent.swapChildren(i - 1, i);
                i = i == 1 ? 2 : i - 1;
            } else {
                i++;
            }
        }

        if (recurse) {
            for (BaseComponent child : parent.getChildren()) {
                sort(child, recurse);
            }
        }
    }
681961
IsolationLevel selectIsolationLevel(Transaction parent, IsolationLevel desiredLevel) {
        if (desiredLevel == null) {
            if (parent == null) {
                desiredLevel = mDefaultIsolationLevel;
            } else {
                desiredLevel = parent.getIsolationLevel();
            }
        } else if (parent != null) {
            IsolationLevel parentLevel = parent.getIsolationLevel();
            // Can promote to higher level, but not lower.
            if (parentLevel.compareTo(desiredLevel) >= 0) {
                desiredLevel = parentLevel;
            } else {
                return null;
            }
        }

        switch (desiredLevel) {
        case NONE:
            return IsolationLevel.NONE;
        case READ_UNCOMMITTED:
            return mReadUncommittedLevel;
        case READ_COMMITTED:
            return mReadCommittedLevel;
        case REPEATABLE_READ:
            return mRepeatableReadLevel;
        case SERIALIZABLE:
            return mSerializableLevel;
        }

        return null;
    }
839598
private void removeIndexTermRecursive(final Element parent) {
        if (parent == null) {
            return;
        }
        final NodeList children = parent.getChildNodes();
        Element child;
        for (int i = children.getLength() - 1; i >= 0; i--) {
            if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
                child = (Element) children.item(i);
                final boolean isIndexTerm = TOPIC_INDEXTERM.matches(child);
                final boolean hasStart = !child.getAttribute(ATTRIBUTE_NAME_START).isEmpty();
                final boolean hasEnd = !child.getAttribute(ATTRIBUTE_NAME_END).isEmpty();
                if (isIndexTerm && (hasStart || hasEnd)) {
                    parent.removeChild(child);
                } else {
                    removeIndexTermRecursive(child);
                }
            }
        }
    }
541272
private void recursiveCollapseAreas(AreaImpl root)
    {
        if (canCollapse(root))
        {
            //System.out.println("Collapsing: " + root);
            recursiveCollapseSubtree(root, root);
            root.removeAllChildren();
        }
        else
        {
            for (int i = 0; i < root.getChildCount(); i++)
                recursiveCollapseAreas((AreaImpl) root.getChildAt(i));
        }
    }
    
    private boolean canCollapse(AreaImpl area)
    {
        return (area.getChildCount() == 1 && area.getChildAt(0).isLeaf());
    }

    private void recursiveCollapseSubtree(AreaImpl src, AreaImpl dest)
    {
        for (int i = 0; i < src.getChildCount(); i++)
        {
            AreaImpl child = (AreaImpl) src.getChildAt(i);
            recursiveCollapseSubtree(child, dest);
            dest.joinChild(child);
        }
    }

    
}
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()
144873
private void secondWalk(TreeNode v, double m, int level, double levelStart) {
		// construct the position from the prelim and the level information

		// The rootLocation affects the way how x and y are changed and in what
		// direction.
		double levelChangeSign = getLevelChangeSign();
		boolean levelChangeOnYAxis = isLevelChangeInYAxis();
		double levelSize = getSizeOfLevel(level);

		double x = getPrelim(v) + m;

		double y;
		AlignmentInLevel alignment = configuration.getAlignmentInLevel();
		if (alignment == AlignmentInLevel.Center) {
			y = levelStart + levelChangeSign * (levelSize / 2);
		} else if (alignment == AlignmentInLevel.TowardsRoot) {
			y = levelStart + levelChangeSign * (getNodeThickness(v) / 2);
		} else {
			y = levelStart + levelSize - levelChangeSign
					* (getNodeThickness(v) / 2);
		}

		if (!levelChangeOnYAxis) {
			double t = x;
			x = y;
			y = t;
		}

		positions.put(v, new NormalizedPosition(x, y));

		// update the bounds
		updateBounds(v, x, y);

		// recurse
		if (!tree.isLeaf(v)) {
			double nextLevelStart = levelStart
					+ (levelSize + configuration.getGapBetweenLevels(level + 1))
					* levelChangeSign;
			for (TreeNode w : tree.getChildren(v)) {
				secondWalk(w, m + getMod(v), level + 1, nextLevelStart);
			}
		}
	}
851753
public final int parentItemPosition(int adapterPosition) {
        int itemCount = 0;
        for (int i = 0; i < parentItemCount(); i++) {
            itemCount += 1;

            if (isExpanded(i)) {
                int childCount = childItemCount(i);
                itemCount += childCount;
            }
            if (adapterPosition < itemCount) {
                return i;
            }
        }

        throw new IllegalStateException("The adapter position is not a parent type: " + adapterPosition);
    }
11408
@UiThread
    @NonNull
    @Override
    public HorizontalParentViewHolder onCreateParentViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.list_item_parent_horizontal, parent, false);
        return new HorizontalParentViewHolder(view);
    }
539551
private int internalRepositionPlaceholder(int x, int y) {

        int indexCorrection = 0;
        int previousTop = 0;
        int documentScrollTop = getElement().getOwnerDocument().getScrollTop();
        int documentScrollLeft = getElement().getOwnerDocument().getScrollLeft();
        for (int index = 0; index < m_elementPositions.size(); index++) {
            ElementPositionInfo info = m_elementPositions.get(index);
            if (info.getElement() == m_placeholder) {
                indexCorrection = 1;
            }
            if (info.isAbsolute() || !info.isVisible()) {
                continue;
            }

            int top = info.getRelativeTop(y, documentScrollTop);

            if ((top <= 0) || (top >= info.getElementPosition().getHeight())) {
                previousTop = top;
                continue;
            }
            int left = info.getRelativeLeft(x, documentScrollLeft);
            if ((left <= 0) || (left >= info.getElementPosition().getWidth())) {
                previousTop = top;
                continue;
            }
            boolean floatSort = info.isFloating() && (top != 0) && (top == previousTop);
            previousTop = top;
            if (info.getElement() != m_placeholder) {
                if (floatSort) {
                    boolean insertBefore = false;
                    if (left < (info.getElementPosition().getWidth() / 2)) {
                        if (info.isFloatLeft()) {
                            insertBefore = true;
                        }
                    } else if (info.isFloatRight()) {
                        insertBefore = true;
                    }
                    if (insertBefore) {
                        getElement().insertBefore(m_placeholder, info.getElement());
                        return index - indexCorrection;
                    } else {
                        getElement().insertAfter(m_placeholder, info.getElement());
                        return (index + 1) - indexCorrection;
                    }
                } else {
                    if (top < (info.getElementPosition().getHeight() / 2)) {
                        getElement().insertBefore(m_placeholder, info.getElement());
                        return index - indexCorrection;
                    } else {
                        getElement().insertAfter(m_placeholder, info.getElement());
                        return (index + 1) - indexCorrection;
                    }
                }
            } else {
                return index;
            }
        }

        // not over any child position
        if ((m_placeholderIndex >= 0) && (m_placeholder.getParentElement() == getElement())) {
            // element is already attached to this parent and no new position available
            // don't do anything
            return m_placeholderIndex;
        }
        int top = CmsDomUtil.getRelativeY(y, getElement());
        int offsetHeight = getElement().getOffsetHeight();
        if ((top >= (offsetHeight / 2))) {
            // over top half, insert as first child
            getElement().insertFirst(m_placeholder);
            return 0;
        }
        // over bottom half, insert as last child
        getElement().appendChild(m_placeholder);
        return getElement().getChildCount() - 1;
    }
897454
private void innerLinearize(
    DeleteStack.Linearizer       xx,
    GBSNode       p)
  {
    xx.depth++;
    if (xx.depth > GBSTree.maxDepth)
      throw new OptimisticDepthException(
        "maxDepth (" + GBSTree.maxDepth +
                 ") exceeded in GBSDeleteFringe.innerLinearize().");

    if (p.leftChild() != null) {
      innerLinearize(xx, p.leftChild());
    }
    if (xx.lastp == null) {
      xx.headp = p;
    }
    else {
      xx.lastp.setChildren(null, p);
    }
    xx.lastp = p;

    if (p.rightChild() != null) {
      innerLinearize(xx, p.rightChild());
    }
    xx.depth--;
  }
968209
void countNonZeroInR( int[] parent ) {
        TriangularSolver_DSCC.postorder(parent,n,post,gwork);
        columnCounts.process(A,parent,post,countsR);
        nz_in_R = 0;
        for (int k = 0; k < n; k++) {
            nz_in_R += countsR[k];
        }
        if( nz_in_R < 0)
            throw new RuntimeException("Too many elements. Numerical overflow in R counts");
    }
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);
            }
        }
    }
522974
private RedBlackTreeNode<Key, Value> balance(RedBlackTreeNode<Key, Value> h) {
	// assert (h != null);

	if (isRed(h.getRight()))
	    h = rotateLeft(h);
	if (isRed(h.getLeft()) && isRed(h.getLeft().getLeft()))
	    h = rotateRight(h);
	if (isRed(h.getLeft()) && isRed(h.getRight()))
	    flipColors(h);

	h.setSize(size(h.getLeft()) + size(h.getRight()) + 1);
	return h;
    }
1062426
private static boolean multiPointCoverageMultiPoint_(
			MultiPoint _multipointA, MultiPoint _multipointB, double tolerance,
			boolean bPerformWithin, boolean bPerformEquals,
			boolean bPerformOverlaps, ProgressTracker progress_tracker) {
		boolean bPerformContains = false;
		MultiPoint multipoint_a;
		MultiPoint multipoint_b;

		if (_multipointA.getPointCount() > _multipointB.getPointCount()) {
			if (bPerformWithin) {
				bPerformWithin = false;
				bPerformContains = true;
			}

			multipoint_a = _multipointB;
			multipoint_b = _multipointA;
		} else {
			multipoint_a = _multipointA;
			multipoint_b = _multipointB;
		}

		AttributeStreamOfInt8 contained = null;

		if (bPerformEquals || bPerformOverlaps || bPerformContains) {
			contained = new AttributeStreamOfInt8(multipoint_b.getPointCount());

			for (int i = 0; i < multipoint_b.getPointCount(); i++)
				contained.write(i, (byte) 0);
		}

		Envelope2D env_a = new Envelope2D();
		Envelope2D env_b = new Envelope2D();
		Envelope2D envInter = new Envelope2D();
		multipoint_a.queryEnvelope2D(env_a);
		multipoint_b.queryEnvelope2D(env_b);
		env_a.inflate(tolerance, tolerance);
		env_b.inflate(tolerance, tolerance);
		envInter.setCoords(env_a);
		envInter.intersect(env_b);

		Point2D ptA = new Point2D();
		Point2D ptB = new Point2D();

		boolean bWithin = true; // starts off true by default

		QuadTreeImpl quadTreeB = InternalUtils.buildQuadTree(
				(MultiPointImpl) (multipoint_b._getImpl()), envInter);
		QuadTreeImpl.QuadTreeIteratorImpl qtIterB = quadTreeB.getIterator();
		double tolerance_sq = tolerance * tolerance;

		for (int vertex_a = 0; vertex_a < multipoint_a.getPointCount(); vertex_a++) {
			multipoint_a.getXY(vertex_a, ptA);

			if (!envInter.contains(ptA)) {
				if (bPerformEquals || bPerformWithin)
					return false;
				else {
					bWithin = false;
					continue;
				}
			}

			boolean bPtACovered = false;
			env_a.setCoords(ptA.x, ptA.y, ptA.x, ptA.y);
			qtIterB.resetIterator(env_a, tolerance);
			for (int elementHandleB = qtIterB.next(); elementHandleB != -1; elementHandleB = qtIterB
					.next()) {
				int vertex_b = quadTreeB.getElement(elementHandleB);
				multipoint_b.getXY(vertex_b, ptB);

				if (Point2D.sqrDistance(ptA, ptB) <= tolerance_sq) {
					if (bPerformEquals || bPerformOverlaps || bPerformContains)
						contained.write(vertex_b, (byte) 1);

					bPtACovered = true;

					if (bPerformWithin)
						break;
				}
			}

			if (!bPtACovered) {
				bWithin = false;

				if (bPerformEquals || bPerformWithin)
					return false;
			}
		}

		if (bPerformOverlaps && bWithin)
			return false;

		if (bPerformWithin)
			return true;

		for (int i = 0; i < multipoint_b.getPointCount(); i++) {
			if (contained.read(i) == 1) {
				if (bPerformOverlaps)
					return true;
			} else {
				if (bPerformEquals || bPerformContains)
					return false;
			}
		}

		if (bPerformOverlaps)
			return false;

		return true;
	}