private IntervalTreeNode <T> Search(IntervalTreeNode <T> parentNode, T lowValue, T highValue)
        {
            while (!object.Equals(parentNode, nilNode) && !AreOverlaping(parentNode, lowValue, highValue))
            {
                if (!object.ReferenceEquals(nilNode, parentNode.LeftChild) && parentNode.LeftChild.Max.CompareTo(lowValue) >= 0)
                {
                    parentNode = parentNode.LeftChild;
                }
                else
                {
                    parentNode = parentNode.RigthChild;
                }
            }

            return(object.ReferenceEquals(parentNode, nilNode) ? null : parentNode);
        }
        private void InsertFixup(IntervalTreeNode <T> node)
        {
            while (node.Parent.Color == NodeColor.Red)
            {
                if (object.ReferenceEquals(node.Parent, node.Parent.Parent.LeftChild))
                {
                    IntervalTreeNode <T> y = node.Parent.Parent.RigthChild;

                    if (y.Color == NodeColor.Red)
                    {
                        node.Parent.Color = NodeColor.Black;

                        y.Color = NodeColor.Black;

                        node.Parent.Parent.Color = NodeColor.Red;

                        node = node.Parent.Parent;
                    }
                    else if (object.ReferenceEquals(node, node.Parent.RigthChild))
                    {
                        node = node.Parent;

                        LeftRotate(node);
                    }
                    else
                    {
                        node.Parent.Color = NodeColor.Black;

                        node.Parent.Parent.Color = NodeColor.Red;

                        RigthRotate(node.Parent.Parent);
                    }
                }
                else if (object.ReferenceEquals(node.Parent, node.Parent.Parent.RigthChild))
                {
                    IntervalTreeNode <T> y = node.Parent.Parent.LeftChild;

                    if (y.Color == NodeColor.Red)
                    {
                        node.Parent.Color = NodeColor.Black;

                        y.Color = NodeColor.Black;

                        node.Parent.Parent.Color = NodeColor.Red;

                        node = node.Parent.Parent;
                    }
                    else if (object.ReferenceEquals(node, node.Parent.LeftChild))
                    {
                        node = node.Parent;

                        RigthRotate(node);
                    }
                    else
                    {
                        node.Parent.Color = NodeColor.Black;

                        node.Parent.Parent.Color = NodeColor.Red;

                        LeftRotate(node.Parent.Parent);
                    }
                }
                if (node.Parent == null)
                {
                    break;
                }
            }

            this.Root.Color = NodeColor.Black;
        }
 private bool AreOverlaping(IntervalTreeNode <T> interval, T low, T high)
 {
     return(interval.Low.CompareTo(high) < 0 && low.CompareTo(interval.High) < 0);
 }
        public IntervalTree(T parentLowValue, T parentHighValue)
        {
            this.count = 1;

            this.Root = new IntervalTreeNode <T>(parentLowValue, parentHighValue, NodeColor.Black);
        }