Example #1
0
        static void RebalanceUntilRoot(SharpTreeNode pos)
        {
            while (pos.listParent != null)
            {
                if (pos == pos.listParent.left)
                {
                    pos = pos.listParent.left = Rebalance(pos);
                }
                else
                {
                    Debug.Assert(pos == pos.listParent.right);
                    pos = pos.listParent.right = Rebalance(pos);
                }
                pos = pos.listParent;
            }
            SharpTreeNode newRoot = Rebalance(pos);

            if (newRoot != pos && pos.treeFlattener != null)
            {
                Debug.Assert(newRoot.treeFlattener == null);
                newRoot.treeFlattener      = pos.treeFlattener;
                pos.treeFlattener          = null;
                newRoot.treeFlattener.root = newRoot;
            }
            Debug.Assert(newRoot.listParent == null);
            newRoot.CheckInvariants();
        }
Example #2
0
 void CheckInvariants()
 {
     Debug.Assert(left == null || left.listParent == this);
     Debug.Assert(right == null || right.listParent == this);
     Debug.Assert(height == 1 + Math.Max(Height(left), Height(right)));
     Debug.Assert(Math.Abs(this.Balance) <= 1);
     Debug.Assert(totalListLength == -1 || totalListLength == (left != null ? left.totalListLength : 0) + (isVisible ? 1 : 0) + (right != null ? right.totalListLength : 0));
     if (left != null)
     {
         left.CheckInvariants();
     }
     if (right != null)
     {
         right.CheckInvariants();
     }
 }