예제 #1
0
 void EnsureRoot(double val)
 {
     if (null == this.root)
     {
         this.root = new IntervalBoundary(val, null);
     }
 }
 private void EnsureRoot(double val)
 {
     if (this.root == null)
     {
         this.root = new IntervalBoundary(val, null);
     }
 }
예제 #3
0
 internal bool MoveNext()
 {
     while (this.nextNode != null)
     {
         this.currentNode = this.nextNode;
         double num = this.currentNode.Value;
         if (this.val < num)
         {
             this.slot     = this.currentNode.LtSlot;
             this.nextNode = this.currentNode.Left;
         }
         else if (this.val > num)
         {
             this.slot     = this.currentNode.GtSlot;
             this.nextNode = this.currentNode.Right;
         }
         else
         {
             this.slot     = this.currentNode.EqSlot;
             this.nextNode = null;
         }
         if (this.slot != null)
         {
             return(true);
         }
     }
     return(false);
 }
 internal IntervalTreeTraverser(double val, IntervalBoundary root)
 {
     this.currentNode = null;
     this.slot = null;
     this.nextNode = root;
     this.val = val;
 }
예제 #5
0
 internal IntervalTreeTraverser(double val, IntervalBoundary root)
 {
     this.currentNode = null;
     this.slot        = null;
     this.nextNode    = root;
     this.val         = val;
 }
예제 #6
0
        void Replace(IntervalBoundary replace, IntervalBoundary with)
        {
            IntervalBoundary parent = replace.Parent;

            if (null != parent)
            {
                if (replace == parent.Left)
                {
                    parent.Left = with;
                }
                else if (replace == parent.Right)
                {
                    parent.Right = with;
                }
            }
            else
            {
                // Replacing root
                this.root = with;
            }
            if (null != with)
            {
                with.Parent = parent;
            }
        }
 internal bool MoveNext()
 {
     while (this.nextNode != null)
     {
         this.currentNode = this.nextNode;
         double num = this.currentNode.Value;
         if (this.val < num)
         {
             this.slot = this.currentNode.LtSlot;
             this.nextNode = this.currentNode.Left;
         }
         else if (this.val > num)
         {
             this.slot = this.currentNode.GtSlot;
             this.nextNode = this.currentNode.Right;
         }
         else
         {
             this.slot = this.currentNode.EqSlot;
             this.nextNode = null;
         }
         if (this.slot != null)
         {
             return true;
         }
     }
     return false;
 }
예제 #8
0
        internal bool MoveNext()
        {
            while (null != this.nextNode)
            {
                this.currentNode = this.nextNode;
                double currentVal = this.currentNode.Value;
                if (val < currentVal)
                {
                    this.slot     = this.currentNode.LtSlot;
                    this.nextNode = this.currentNode.Left;
                }
                else if (val > currentVal)
                {
                    this.slot     = this.currentNode.GtSlot;
                    this.nextNode = this.currentNode.Right;
                }
                else
                {
                    this.slot     = this.currentNode.EqSlot;
                    this.nextNode = null;
                }
                if (null != this.slot)
                {
                    return(true);
                }
            }

            return(false);
        }
 internal IntervalBoundary EnsureLeft(double val)
 {
     if (this.left == null)
     {
         this.left = new IntervalBoundary(val, this);
     }
     return this.left;
 }
 internal IntervalBoundary EnsureRight(double val)
 {
     if (this.right == null)
     {
         this.right = new IntervalBoundary(val, this);
     }
     return this.right;
 }
예제 #11
0
 internal IntervalBoundary EnsureRight(double val)
 {
     if (this.right == null)
     {
         this.right = new IntervalBoundary(val, this);
     }
     return(this.right);
 }
예제 #12
0
 internal IntervalBoundary EnsureLeft(double val)
 {
     if (this.left == null)
     {
         this.left = new IntervalBoundary(val, this);
     }
     return(this.left);
 }
        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);
                }
            }
        }
 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);
         }
     }
 }
예제 #15
0
        void RemoveBoundary(IntervalBoundary boundary)
        {
            IntervalCollection replacementIntervals = null;
            int replacementCount = 0;

            if (null != boundary.Left && null != boundary.Right)
            {
                // Neither left/right are null. Typical binary tree node removal - replace the removed node
                // with the symmetric order predecessor
                IntervalBoundary replacement = boundary.Left;
                while (null != replacement.Right)
                {
                    replacement = replacement.Right;
                }
                // Find all intervals with endpoint y in the tree
                replacementIntervals = this.intervals.GetIntervalsWithEndPoint(replacement.Value);

                // Remove the intervals from the tree
                replacementCount = replacementIntervals.Count;
                for (int i = 0; i < replacementCount; ++i)
                {
                    this.RemoveIntervalFromTree(replacementIntervals[i]);
                }

                double val = boundary.Value;
                boundary.Value    = replacement.Value;
                replacement.Value = val;
                boundary          = replacement;
            }

            if (null != boundary.Left)
            {
                this.Replace(boundary, boundary.Left);
            }
            else
            {
                this.Replace(boundary, boundary.Right);
            }

            // Discard the node
            boundary.Parent = null;
            boundary.Left   = null;
            boundary.Right  = null;

            // Reinstall Intervals
            for (int i = 0; i < replacementCount; ++i)
            {
                this.AddIntervalToTree(replacementIntervals[i]);
            }
        }
        internal IntervalBoundary FindBoundaryNode(IntervalBoundary root, double val)
        {
            IntervalBoundary boundary = null;

            if (root != null)
            {
                if (root.Value == val)
                {
                    return(root);
                }
                boundary = this.FindBoundaryNode(root.Left, val);
                if (boundary == null)
                {
                    boundary = this.FindBoundaryNode(root.Right, val);
                }
            }
            return(boundary);
        }
예제 #17
0
        internal IntervalBoundary FindBoundaryNode(IntervalBoundary root, double val)
        {
            IntervalBoundary boundary = null;

            if (null != root)
            {
                if (root.Value == val)
                {
                    boundary = root;
                }
                else
                {
                    if (null == (boundary = this.FindBoundaryNode(root.Left, val)))
                    {
                        boundary = this.FindBoundaryNode(root.Right, val);
                    }
                }
            }
            return(boundary);
        }
        private void RemoveBoundary(IntervalBoundary boundary)
        {
            IntervalCollection intervalsWithEndPoint = null;
            int count = 0;

            if ((boundary.Left != null) && (boundary.Right != null))
            {
                IntervalBoundary left = boundary.Left;
                while (left.Right != null)
                {
                    left = left.Right;
                }
                intervalsWithEndPoint = this.intervals.GetIntervalsWithEndPoint(left.Value);
                count = intervalsWithEndPoint.Count;
                for (int j = 0; j < count; j++)
                {
                    this.RemoveIntervalFromTree(intervalsWithEndPoint[j]);
                }
                double num3 = boundary.Value;
                boundary.Value = left.Value;
                left.Value     = num3;
                boundary       = left;
            }
            if (boundary.Left != null)
            {
                this.Replace(boundary, boundary.Left);
            }
            else
            {
                this.Replace(boundary, boundary.Right);
            }
            boundary.Parent = null;
            boundary.Left   = null;
            boundary.Right  = null;
            for (int i = 0; i < count; i++)
            {
                this.AddIntervalToTree(intervalsWithEndPoint[i]);
            }
        }
        private void Replace(IntervalBoundary replace, IntervalBoundary with)
        {
            IntervalBoundary parent = replace.Parent;

            if (parent != null)
            {
                if (replace == parent.Left)
                {
                    parent.Left = with;
                }
                else if (replace == parent.Right)
                {
                    parent.Right = with;
                }
            }
            else
            {
                this.root = with;
            }
            if (with != null)
            {
                with.Parent = parent;
            }
        }
예제 #20
0
 internal IntervalBoundary(double val, IntervalBoundary parent)
 {
     this.val    = val;
     this.parent = parent;
 }
 private void EnsureRoot(double val)
 {
     if (this.root == null)
     {
         this.root = new IntervalBoundary(val, null);
     }
 }
 internal IntervalBoundary FindBoundaryNode(IntervalBoundary root, double val)
 {
     IntervalBoundary boundary = null;
     if (root != null)
     {
         if (root.Value == val)
         {
             return root;
         }
         boundary = this.FindBoundaryNode(root.Left, val);
         if (boundary == null)
         {
             boundary = this.FindBoundaryNode(root.Right, val);
         }
     }
     return boundary;
 }
 internal IntervalBoundary(double val, IntervalBoundary parent)
 {
     this.val = val;
     this.parent = parent;
 }
예제 #24
0
 void Replace(IntervalBoundary replace, IntervalBoundary with)
 {
     IntervalBoundary parent = replace.Parent;
     if (null != parent)
     {
         if (replace == parent.Left)
         {
             parent.Left = with;
         }
         else if (replace == parent.Right)
         {
             parent.Right = with;
         }
     }
     else
     {
         // Replacing root
         this.root = with;
     }
     if (null != with)
     {
         with.Parent = parent;
     }
 }
예제 #25
0
        void RemoveBoundary(IntervalBoundary boundary)
        {
            IntervalCollection replacementIntervals = null;
            int replacementCount = 0;

            if (null != boundary.Left && null != boundary.Right)
            {
                // Neither left/right are null. Typical binary tree node removal - replace the removed node
                // with the symmetric order predecessor
                IntervalBoundary replacement = boundary.Left;
                while (null != replacement.Right)
                {
                    replacement = replacement.Right;
                }
                // Find all intervals with endpoint y in the tree
                replacementIntervals = this.intervals.GetIntervalsWithEndPoint(replacement.Value);

                // Remove the intervals from the tree
                replacementCount = replacementIntervals.Count;
                for (int i = 0; i < replacementCount; ++i)
                {
                    this.RemoveIntervalFromTree(replacementIntervals[i]);
                }

                double val = boundary.Value;
                boundary.Value = replacement.Value;
                replacement.Value = val;
                boundary = replacement;
            }

            if (null != boundary.Left)
            {
                this.Replace(boundary, boundary.Left);
            }
            else
            {
                this.Replace(boundary, boundary.Right);
            }

            // Discard the node
            boundary.Parent = null;
            boundary.Left = null;
            boundary.Right = null;

            // Reinstall Intervals
            for (int i = 0; i < replacementCount; ++i)
            {
                this.AddIntervalToTree(replacementIntervals[i]);
            }
        }
예제 #26
0
 internal IntervalBoundary FindBoundaryNode(IntervalBoundary root, double val)
 {
     IntervalBoundary boundary = null;
     if (null != root)
     {
         if (root.Value == val)
         {
             boundary = root;
         }
         else
         {
             if (null == (boundary = this.FindBoundaryNode(root.Left, val)))
             {
                 boundary = this.FindBoundaryNode(root.Right, val);
             }
         }
     }
     return boundary;
 }
예제 #27
0
 void EnsureRoot(double val)
 {
     if (null == this.root)
     {
         this.root = new IntervalBoundary(val, null);
     }
 }
예제 #28
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;
            }
        }
예제 #29
0
        internal bool MoveNext()
        {
            while (null != this.nextNode)
            {
                this.currentNode = this.nextNode;
                double currentVal = this.currentNode.Value;
                if (val < currentVal)
                {
                    this.slot = this.currentNode.LtSlot;
                    this.nextNode = this.currentNode.Left;
                }
                else if (val > currentVal)
                {
                    this.slot = this.currentNode.GtSlot;
                    this.nextNode = this.currentNode.Right;
                }
                else
                {
                    this.slot = this.currentNode.EqSlot;
                    this.nextNode = null;
                }
                if (null != this.slot)
                {
                    return true;
                }
            }

            return false;
        }
 private void RemoveBoundary(IntervalBoundary boundary)
 {
     IntervalCollection intervalsWithEndPoint = null;
     int count = 0;
     if ((boundary.Left != null) && (boundary.Right != null))
     {
         IntervalBoundary left = boundary.Left;
         while (left.Right != null)
         {
             left = left.Right;
         }
         intervalsWithEndPoint = this.intervals.GetIntervalsWithEndPoint(left.Value);
         count = intervalsWithEndPoint.Count;
         for (int j = 0; j < count; j++)
         {
             this.RemoveIntervalFromTree(intervalsWithEndPoint[j]);
         }
         double num3 = boundary.Value;
         boundary.Value = left.Value;
         left.Value = num3;
         boundary = left;
     }
     if (boundary.Left != null)
     {
         this.Replace(boundary, boundary.Left);
     }
     else
     {
         this.Replace(boundary, boundary.Right);
     }
     boundary.Parent = null;
     boundary.Left = null;
     boundary.Right = null;
     for (int i = 0; i < count; i++)
     {
         this.AddIntervalToTree(intervalsWithEndPoint[i]);
     }
 }
 private void Replace(IntervalBoundary replace, IntervalBoundary with)
 {
     IntervalBoundary parent = replace.Parent;
     if (parent != null)
     {
         if (replace == parent.Left)
         {
             parent.Left = with;
         }
         else if (replace == parent.Right)
         {
             parent.Right = with;
         }
     }
     else
     {
         this.root = with;
     }
     if (with != null)
     {
         with.Parent = parent;
     }
 }
예제 #32
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;
            }
        }