// 1) The root is black
        // 2) All leaves are black
        // 3) Every red node must have two black child nodes
        // 4) Every path from a given node to any of its descendant leaves must contain an equal number of black nodes

        private void CheckNode(RedBlackNode <T> node)
        {
            RedBlackNode <T> left  = (RedBlackNode <T>)node.Left;
            RedBlackNode <T> right = (RedBlackNode <T>)node.Right;

            if (left.BlackHeight != right.BlackHeight)
            {
                // rotate
                // make left node red and checknode
                // make right node red and checknode
            }

            if (node.Color.Equals(NodeColors.Red))
            {
                if (node.Equals(this.Root) || left.Color.Equals(NodeColors.Red) || right.Color.Equals(NodeColors.Red))
                {
                    node.Color = NodeColors.Black;
                }
            }
        }
Beispiel #2
0
 public static bool operator ==(ValueTree tree1, ValueTree tree2)
 {
     return(RedBlackNode <EquatableObject> .Equals(tree1._root, tree2._root));
 }
Beispiel #3
0
 public static bool operator ==(TypeTree tree1, TypeTree tree2)
 {
     return(RedBlackNode <DType> .Equals(tree1._root, tree2._root));
 }