Ejemplo n.º 1
0
            private static void smethod_7(
                ref RedBlackTree <T> .Node root,
                RedBlackTree <T> .Node parent,
                RedBlackTree <T> .Node child)
            {
                RedBlackTree <T> .Node node1 = child.node_1;
                RedBlackTree <T> .Node node2 = child.node_2;
                RedBlackTree <T> .Node node0 = child.node_0;
                bool isLeft = child.node_0.node_1 == child;
                bool bool0  = child.bool_0;

                if (parent.node_0 == null)
                {
                    root        = child;
                    root.node_0 = (RedBlackTree <T> .Node)null;
                }
                else if (parent.node_0.node_1 == parent)
                {
                    parent.node_0.Left = child;
                }
                else
                {
                    parent.node_0.Right = child;
                }
                if (parent.node_1 == child)
                {
                    child.Left  = parent;
                    child.Right = parent.node_2;
                }
                else if (parent.node_2 == child)
                {
                    child.Left  = parent.node_1;
                    child.Right = parent;
                }
                else
                {
                    child.Left  = parent.node_1;
                    child.Right = parent.node_2;
                    node0.method_1(isLeft, parent);
                }
                child.bool_0  = parent.bool_0;
                parent.Left   = node1;
                parent.Right  = node2;
                parent.bool_0 = bool0;
            }
Ejemplo n.º 2
0
            internal void method_6(ref RedBlackTree <T> .Node root)
            {
                if (this.node_1 != null && this.node_2 != null)
                {
                    RedBlackTree <T> .Node rightMost = this.node_1.GetRightMost();
                    RedBlackTree <T> .Node.smethod_7(ref root, this, rightMost);
                }
                if (this.node_1 == null && this.node_2 == null)
                {
                    RedBlackTree <T> .Node sibling = this.Sibling;
                    RedBlackTree <T> .Node.smethod_8(ref root, this, (RedBlackTree <T> .Node) null);

                    if (!this.bool_0)
                    {
                        bool parentsNeedRebalancing  = true;
                        RedBlackTree <T> .Node root1 = this.node_0;
                        if (root1 != null)
                        {
                            while (parentsNeedRebalancing)
                            {
                                bool flag = root == root1;
                                RedBlackTree <T> .Node parent = root1.Parent;
                                bool isLeft = parent != null && parent.Left == root1;
                                RedBlackTree <T> .Node child = sibling != sibling.Parent.Left ? RedBlackTree <T> .Node.smethod_6(root1, sibling, out parentsNeedRebalancing) : RedBlackTree <T> .Node.smethod_5(root1, sibling, out parentsNeedRebalancing);

                                if (flag)
                                {
                                    root        = child;
                                    root.Parent = (RedBlackTree <T> .Node)null;
                                }
                                else
                                {
                                    parent.method_1(isLeft, child);
                                }
                                sibling = child.Sibling;
                                root1   = child.Parent;
                                if (root1 == null || sibling == null)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    RedBlackTree <T> .Node replacement = this.node_1 != null ? this.node_1 : this.node_2;
                    RedBlackTree <T> .Node.smethod_8(ref root, this, replacement);

                    if (!this.bool_0)
                    {
                        if (!replacement.bool_0)
                        {
                            throw new Exception();
                        }
                        replacement.bool_0 = false;
                    }
                }
                if (root == null)
                {
                    return;
                }
                root.bool_0 = false;
            }
Ejemplo n.º 3
0
            internal int method_5(T value, IComparer <T> comparer)
            {
                int num1 = 0;

                RedBlackTree <T> .Node node1 = (RedBlackTree <T> .Node)null;
                RedBlackTree <T> .Node root1 = (RedBlackTree <T> .Node)null;
                RedBlackTree <T> .Node root2 = this;
                bool isLeft1 = false;

                RedBlackTree <T> .Node node2 = root2.method_2(false);
                while (node2 != null)
                {
                    bool isLeft2 = isLeft1;
                    RedBlackTree <T> .Node node3 = root1;
                    root1 = root2;
                    root2 = node2;
                    int num2 = comparer.Compare(value, root2.gparam_0);
                    isLeft1 = num2 < 0;
                    if (num2 == 0)
                    {
                        node1 = root2;
                    }
                    node2 = root2.method_2(isLeft1);
                    if (!root2.IsRed && !RedBlackTree <T> .Node.smethod_0(node2))
                    {
                        if (RedBlackTree <T> .Node.smethod_0(root2.method_2(!isLeft1)))
                        {
                            RedBlackTree <T> .Node child = isLeft1 ? RedBlackTree <T> .Node.smethod_3(root2) : RedBlackTree <T> .Node.smethod_1(root2);

                            root1.method_1(isLeft2, child);
                            root1 = child;
                        }
                        else
                        {
                            RedBlackTree <T> .Node node4 = root1.method_2(!isLeft2);
                            if (node4 != null)
                            {
                                if (!RedBlackTree <T> .Node.smethod_0(node4.node_1) && !RedBlackTree <T> .Node.smethod_0(node4.node_2))
                                {
                                    root1.bool_0 = false;
                                    node4.bool_0 = true;
                                    root2.bool_0 = true;
                                }
                                else
                                {
                                    bool isLeft3 = root1 != node3.node_2;
                                    RedBlackTree <T> .Node child;
                                    if (RedBlackTree <T> .Node.smethod_0(node4.method_2(isLeft2)))
                                    {
                                        child = isLeft2 ? RedBlackTree <T> .Node.smethod_4(root1) : RedBlackTree <T> .Node.smethod_2(root1);

                                        node3.method_1(isLeft3, child);
                                    }
                                    else if (RedBlackTree <T> .Node.smethod_0(node4.method_2(!isLeft2)))
                                    {
                                        child = isLeft2 ? RedBlackTree <T> .Node.smethod_3(root1) : RedBlackTree <T> .Node.smethod_1(root1);

                                        node3.method_1(isLeft3, child);
                                    }
                                    else
                                    {
                                        child = node3.method_2(isLeft3);
                                    }
                                    RedBlackTree <T> .Node node5 = root2;
                                    child.bool_0        = true;
                                    node5.bool_0        = true;
                                    child.node_1.bool_0 = false;
                                    child.node_2.bool_0 = false;
                                }
                            }
                        }
                    }
                }
                if (node1 != null)
                {
                    node1.gparam_0 = root2.gparam_0;
                    root1.method_1(root1.Right != root2, root2.method_2(root2.Left == null));
                    num1 = 1;
                }
                return(num1);
            }
Ejemplo n.º 4
0
            internal RedBlackTree <T> .Node method_4(T value, IComparer <T> comparer)
            {
                bool isLeft1 = false;
                bool flag    = false;

                RedBlackTree <T> .Node node1 = this;
                RedBlackTree <T> .Node root  = (RedBlackTree <T> .Node)null;
                RedBlackTree <T> .Node node2 = (RedBlackTree <T> .Node)null;
                RedBlackTree <T> .Node node3;
                for (RedBlackTree <T> .Node node4 = this.node_2; node4 != null; node4 = isLeft1 ? node4.node_1 : node4.node_2)
                {
                    if (node4.node_1 != null && node4.node_1.bool_0 && (node4.node_2 != null && node4.node_2.bool_0))
                    {
                        node4.bool_0        = true;
                        node4.node_1.bool_0 = false;
                        node4.node_2.bool_0 = false;
                        if (RedBlackTree <T> .Node.smethod_0(node2))
                        {
                            bool isLeft2 = node1.node_1 == root;
                            if (isLeft1 == flag)
                            {
                                node1.method_1(isLeft2, flag ? RedBlackTree <T> .Node.smethod_1(root) : RedBlackTree <T> .Node.smethod_3(root));
                            }
                            else
                            {
                                node1.method_1(isLeft2, flag ? RedBlackTree <T> .Node.smethod_2(root) : RedBlackTree <T> .Node.smethod_4(root));
                            }
                        }
                    }
                    else if (node4.bool_0 && RedBlackTree <T> .Node.smethod_0(node2))
                    {
                        bool isLeft2 = node1.node_1 == root;
                        if (isLeft1 == flag)
                        {
                            node1.method_1(isLeft2, flag ? RedBlackTree <T> .Node.smethod_1(root) : RedBlackTree <T> .Node.smethod_3(root));
                        }
                        else
                        {
                            node1.method_1(isLeft2, flag ? RedBlackTree <T> .Node.smethod_2(root) : RedBlackTree <T> .Node.smethod_4(root));
                        }
                    }
                    int num = comparer.Compare(value, node4.gparam_0);
                    if (num != 0)
                    {
                        flag    = isLeft1;
                        isLeft1 = num < 0;
                        if (root != null)
                        {
                            node1 = root;
                        }
                        root  = node2;
                        node2 = node4;
                    }
                    else
                    {
                        node3 = (RedBlackTree <T> .Node)null;
                        goto label_20;
                    }
                }
                RedBlackTree <T> .Node child;
                node3 = child = new RedBlackTree <T> .Node(value);

                node2.method_1(isLeft1, child);
                if (node2.bool_0)
                {
                    bool isLeft2 = node1.node_1 == root;
                    if (isLeft1 == flag)
                    {
                        node1.method_1(isLeft2, flag ? RedBlackTree <T> .Node.smethod_1(root) : RedBlackTree <T> .Node.smethod_3(root));
                    }
                    else
                    {
                        node1.method_1(isLeft2, flag ? RedBlackTree <T> .Node.smethod_2(root) : RedBlackTree <T> .Node.smethod_4(root));
                    }
                }
label_20:
                return(node3);
            }
Ejemplo n.º 5
0
 public void ReverseNodes(RedBlackTree <T> .Node first, RedBlackTree <T> .Node last)
 {
     if (first == last)
     {
         return;
     }
     RedBlackTree <T> .Node child1 = first;
     RedBlackTree <T> .Node child2 = last;
     while (true)
     {
         RedBlackTree <T> .Node next     = child1.GetNext();
         RedBlackTree <T> .Node previous = child2.GetPrevious();
         bool flag = next == previous || next == child2;
         if (child1.Parent == child2)
         {
             RedBlackTree <T> .Node node = child1;
             child1 = child2;
             child2 = node;
         }
         RedBlackTree <T> .Node left1   = child1.Left;
         RedBlackTree <T> .Node right1  = child1.Right;
         RedBlackTree <T> .Node parent1 = child1.Parent;
         bool isRed1 = child1.IsRed;
         RedBlackTree <T> .Node left2   = child2.Left;
         RedBlackTree <T> .Node right2  = child2.Right;
         RedBlackTree <T> .Node parent2 = child2.Parent;
         bool isRed2 = child2.IsRed;
         if (child1.Right == child2)
         {
             child1.Left  = left2;
             child1.Right = right2;
             child2.Left  = left1;
             child2.Right = child1;
             if (parent1 == null)
             {
                 this.node_0   = child2;
                 child2.Parent = (RedBlackTree <T> .Node)null;
             }
             else
             {
                 parent1.method_1(parent1.Left == child1, child2);
             }
         }
         else if (child1.Left == child2)
         {
             child1.Left  = left2;
             child1.Right = right2;
             child2.Left  = child1;
             child2.Right = right1;
             if (parent1 == null)
             {
                 this.node_0   = child2;
                 child2.Parent = (RedBlackTree <T> .Node)null;
             }
             else
             {
                 parent1.method_1(parent1.Left == child1, child2);
             }
         }
         else
         {
             child1.Left  = left2;
             child1.Right = right2;
             if (parent2 == null)
             {
                 this.node_0   = child1;
                 child1.Parent = (RedBlackTree <T> .Node)null;
             }
             else
             {
                 parent2.method_1(parent2.Left == child2, child1);
             }
             child2.Left  = left1;
             child2.Right = right1;
             if (parent1 == null)
             {
                 this.node_0   = child2;
                 child2.Parent = (RedBlackTree <T> .Node)null;
             }
             else
             {
                 parent1.method_1(parent1.Left == child1, child2);
             }
         }
         child1.IsRed = isRed2;
         child2.IsRed = isRed1;
         if (!flag)
         {
             child1 = next;
             child2 = previous;
         }
         else
         {
             break;
         }
     }
 }