Beispiel #1
0
 ///<summary>
 ///Set parent node
 ///</summary>
 internal override void SetParent(RBTreeNodeBase <T, RBOrderedNodeParam> value)
 {
     mParent = value;
     if (mParent != null)
     {
         mParent.OnUpdateCount();
     }
 }
Beispiel #2
0
        ///<summary>
        /// Rotate our tree Right
        ///
        ///             X                                         Y
        ///           /   \                                     /   \
        ///          A     Y     <---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();
        }
Beispiel #3
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();
        }