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

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

Label_0018:
            num = root.Value;
            if (num > interval.UpperBound)
            {
                root = add ? root.EnsureLeft(interval.UpperBound) : root.Left;
                goto Label_0018;
            }
            if ((boundary2 != null) && (boundary2.Value >= interval.LowerBound))
            {
                if (add)
                {
                    root.AddToLtSlot(interval);
                }
                else
                {
                    root.RemoveFromLtSlot(interval);
                }
            }
            if (num < interval.UpperBound)
            {
                if (num > interval.LowerBound)
                {
                    if (add)
                    {
                        root.AddToEqSlot(interval);
                    }
                    else
                    {
                        root.RemoveFromEqSlot(interval);
                    }
                }
                boundary2 = root;
                root      = add ? root.EnsureRight(interval.UpperBound) : root.Right;
                goto Label_0018;
            }
            if (IntervalOp.LessThanEquals == interval.UpperOp)
            {
                if (add)
                {
                    root.AddToEqSlot(interval);
                }
                else
                {
                    root.RemoveFromEqSlot(interval);
                }
            }
        }
Esempio n. 2
0
        void EditRight(Interval interval, bool add)
        {
            if (add)
            {
                this.EnsureRoot(interval.UpperBound);
            }

            IntervalBoundary root          = this.root;
            IntervalBoundary rightAncestor = null;

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

                if (rootVal > interval.UpperBound)
                {
                    // root is outside the interval range because it is > the upper bound
                    root = add ? root.EnsureLeft(interval.UpperBound) : root.Left;
                    continue;
                }

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

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

                // upperBound == rootVal. We're done.
                // If upperBound == lowerBound, we already inserted this when doing AddLeft
                if (IntervalOp.LessThanEquals == interval.UpperOp)
                {
                    // If the range is inclusive of the upper bound, then since this node == upperBound,
                    // it must be in the range.
                    if (add)
                    {
                        root.AddToEqSlot(interval);
                    }
                    else
                    {
                        root.RemoveFromEqSlot(interval);
                    }
                }
                break;
            }
        }