예제 #1
0
        protected void RightRotate(RBTreeNodeBase <T, P> y)
        {
            RBTreeNodeBase <T, P> mLeft = y.mLeft;

            y.mLeft = mLeft.mRight;
            if (mLeft.mRight != null)
            {
                mLeft.mRight.mParent = y;
            }
            mLeft.mParent = y.mParent;
            if (y.mParent == null)
            {
                this.mRoot = mLeft;
            }
            else if (y == y.mParent.mLeft)
            {
                y.mParent.mLeft = mLeft;
            }
            else
            {
                y.mParent.mRight = mLeft;
            }
            mLeft.mRight = y;
            y.mParent    = mLeft;
            y.OnUpdateCount();
        }
예제 #2
0
        protected void LeftRotate(RBTreeNodeBase <T, P> x)
        {
            RBTreeNodeBase <T, P> mRight = x.mRight;

            x.mRight = mRight.mLeft;
            if (mRight.mLeft != null)
            {
                mRight.mLeft.mParent = x;
            }
            mRight.mParent = x.mParent;
            if (x.mParent == null)
            {
                this.mRoot = mRight;
            }
            else if (x == x.mParent.mLeft)
            {
                x.mParent.mLeft = mRight;
            }
            else
            {
                x.mParent.mRight = mRight;
            }
            mRight.mLeft = x;
            x.mParent    = mRight;
            x.OnUpdateCount();
        }
예제 #3
0
 ///<summary>
 ///Set parent node
 ///</summary>
 internal override void SetParent(RBTreeNodeBase <T, RBOrderedNodeParam> value)
 {
     mParent = value;
     if (mParent != null)
     {
         mParent.OnUpdateCount();
     }
 }
예제 #4
0
        ///<summary>
        /// Rotate our tree Right
        ///
        ///             X                                         Y
        ///           /   \                                     /   \
        ///          A     Y     leftArrow--rb_right_rotate(Y)        X     C
        ///              /   \                               /   \
        ///             B     C                             A     B
        ///
        /// N.B. This does not change the ordering.
        ///
        /// We assume that neither X or Y is NULL
        ///</summary>>
        protected void RightRotate(RBTreeNodeBase <T, P> y)
        {
            RBTreeNodeBase <T, P> x;

            // set X
            x = y.mLeft;

            // Turn X's right subtree into Y's left subtree (move B)
            y.mLeft = x.mRight;

            // If B is not null, set it's parent to be Y
            if (x.mRight != null)
            {
                x.mRight.mParent = y;
            }

            // Set X's parent to be what Y's parent was
            x.mParent = y.mParent;

            // if Y was the root
            if (y.mParent == null)
            {
                mRoot = x;
            }
            else
            {
                // Set Y's parent's left or right pointer to be X
                if (y == y.mParent.mLeft)
                {
                    y.mParent.mLeft = x;
                }
                else
                {
                    y.mParent.mRight = x;
                }
            }

            // Put Y on X's right
            x.mRight = y;

            // Set Y's parent to be X
            y.mParent = x;

            y.OnUpdateCount();
        }
예제 #5
0
        ///<summary>
        /// Rotate our tree Left
        ///
        ///             X        rb_left_rotate(X)--->            Y
        ///           /   \                                     /   \
        ///          A     Y                                   X     C
        ///              /   \                               /   \
        ///             B     C                             A     B
        ///
        /// N.B. This does not change the ordering.
        ///
        /// We assume that neither X or Y is NULL
        /// </summary>
        protected void LeftRotate(RBTreeNodeBase <T, P> x)
        {
            RBTreeNodeBase <T, P> y;

            // set Y
            y = x.mRight;

            // Turn Y's left subtree into X's right subtree (move B)
            x.mRight = y.mLeft;

            // If B is not null, set it's parent to be X
            if (y.mLeft != null)
            {
                y.mLeft.mParent = x;
            }

            // Set Y's parent to be what X's parent was
            y.mParent = x.mParent;

            // if X was the root
            if (x.mParent == null)
            {
                mRoot = y;
            }
            else
            {
                // Set X's parent's left or right pointer to be Y
                if (x == x.mParent.mLeft)
                {
                    x.mParent.mLeft = y;
                }
                else
                {
                    x.mParent.mRight = y;
                }
            }

            // Put X on Y's left
            y.mLeft = x;

            // Set X's parent to be Y
            x.mParent = y;

            x.OnUpdateCount();
        }