Ejemplo n.º 1
0
        internal static RedBlackNode BalanceLeftDelete(object key, object val, RedBlackNode del, RedBlackNode right)
        {
            if (del is RedNode)
            {
                return(MakeRed(key, val, del.Blacken(), right));
            }
            else if (right is BlackNode)
            {
                return(RightBalance(key, val, del, right.Redden()));
            }
            else if (right is RedNode && right.Left is BlackNode)
            {
                return(MakeRed(right.Left.Key, right.Left.Value,
                               MakeBlack(key, val, del, right.Left.Left),
                               RightBalance(right.Key, right.Value, right.Left.Right, right.Right.Redden())));
            }

            throw new InvalidOperationException("Invariant violation");
        }
Ejemplo n.º 2
0
 internal static RedBlackNode BalanceRightDelete(object key, object val, RedBlackNode left, RedBlackNode del)
 {
     if (del is RedNode)
     {
         return(MakeRed(key, val, left, del.Blacken()));
     }
     else if (left is BlackNode)
     {
         return(LeftBalance(key, val, left.Redden(), del));
     }
     else if (left is RedNode && left.Right is BlackNode)
     {
         return(MakeRed(left.Right.Key, left.Right.Value,
                        LeftBalance(left.Key, left.Value, left.Left.Redden(), left.Right.Left),
                        MakeBlack(key, val, left.Right.Right, del)));
     }
     else
     {
         throw new InvalidOperationException("Invariant violation");
     }
 }