private void EditLeft(Interval interval, bool add)
        {
            double num;

            if (add)
            {
                this.EnsureRoot(interval.LowerBound);
            }
            IntervalBoundary root      = this.root;
            IntervalBoundary boundary2 = null;

Label_0018:
            num = root.Value;
            if (num < interval.LowerBound)
            {
                root = add ? root.EnsureRight(interval.LowerBound) : root.Right;
                goto Label_0018;
            }
            if ((boundary2 != null) && (boundary2.Value <= interval.UpperBound))
            {
                if (add)
                {
                    root.AddToGtSlot(interval);
                }
                else
                {
                    root.RemoveFromGtSlot(interval);
                }
            }
            if (num > interval.LowerBound)
            {
                if (num < interval.UpperBound)
                {
                    if (add)
                    {
                        root.AddToEqSlot(interval);
                    }
                    else
                    {
                        root.RemoveFromEqSlot(interval);
                    }
                }
                boundary2 = root;
                root      = add ? root.EnsureLeft(interval.LowerBound) : root.Left;
                goto Label_0018;
            }
            if (IntervalOp.LessThanEquals == interval.LowerOp)
            {
                if (add)
                {
                    root.AddToEqSlot(interval);
                }
                else
                {
                    root.RemoveFromEqSlot(interval);
                }
            }
        }
示例#2
0
        void EditLeft(Interval interval, bool add)
        {
            if (add)
            {
                this.EnsureRoot(interval.LowerBound);
            }

            IntervalBoundary root         = this.root;
            IntervalBoundary leftAncestor = null;

            while (true)
            {
                double rootVal = root.Value;

                if (rootVal < interval.LowerBound)
                {
                    // root is outside the interval range because it is < the lower bound
                    root = add ? root.EnsureRight(interval.LowerBound) : root.Right;
                    continue;
                }

                // rootVal is >= to interval.lowerBound
                //
                // All values in thee subtree at 'root' are < leftAncestor.Value
                // All values to the left of this node cannot be in the interval because they are < the interval's
                // lower bound.
                // Values to the right of this node lie in range (root.Value to leftAncestor.Value)
                // Thus, the entire right subtree of root will be inside the range if the interval.upperBound
                // is >= leftAncestor.Value
                if (null != leftAncestor && leftAncestor.Value <= interval.UpperBound)
                {
                    if (add)
                    {
                        root.AddToGtSlot(interval);
                    }
                    else
                    {
                        root.RemoveFromGtSlot(interval);
                    }
                }

                if (rootVal > interval.LowerBound)
                { // This node itself lies in the range if it is also < the upper bound
                    if (rootVal < interval.UpperBound)
                    {
                        if (add)
                        {
                            root.AddToEqSlot(interval);
                        }
                        else
                        {
                            root.RemoveFromEqSlot(interval);
                        }
                    }
                    leftAncestor = root;
                    root         = add ? root.EnsureLeft(interval.LowerBound) : root.Left;
                    continue;
                }

                // lowerBound == rootVal. We're done.
                if (IntervalOp.LessThanEquals == interval.LowerOp)
                {
                    // If the range is inclusive of the lower bound (>=), then since this node == lowerBound,
                    // it must be in the range.
                    if (add)
                    {
                        root.AddToEqSlot(interval);
                    }
                    else
                    {
                        root.RemoveFromEqSlot(interval);
                    }
                }
                break;
            }
        }