/// <summary>
        /// Adds the specified <see cref="BraidedTreeNode{TKey, TValue}"/> to the linked list,
        /// sorted after the current instance.</summary>
        /// <param name="node">
        /// The <see cref="BraidedTreeNode{TKey, TValue}"/> to add.</param>
        /// <remarks>
        /// <b>AddList</b> updates the chains of <see cref="Previous"/> and <see cref="Next"/>
        /// references so that the specified <paramref name="node"/> is sorted immediately after the
        /// current instance.</remarks>

        private void AddList(BraidedTreeNode <TKey, TValue> node)
        {
            node._next           = _next;
            node._previous       = this;
            _next                = node;
            node._next._previous = node;
        }
        /// <summary>
        /// Removes the <see cref="BraidedTreeNode{TKey, TValue}"/>, which must be a leaf node, from
        /// the tree structure.</summary>
        /// <remarks><para>
        /// <b>RemoveTree</b> sets the <see cref="Left"/> or <see cref="Right"/> reference of the
        /// <see cref="Parent"/> node, whichever matches the current instance, to a null reference,
        /// and updates the chains of <see cref="Previous"/> and <see cref="Next"/> references to
        /// exclude the current instance.
        /// </para><para>
        /// All <see cref="BraidedTreeNode{TKey, TValue}"/> references of the current instance are
        /// reset to default values, as with <see cref="Clear"/>. Moreover, <b>RemoveTree</b> sets
        /// the <see cref="Tree"/> property to a null reference.</para></remarks>

        internal void RemoveTree()
        {
            Debug.Assert(_left == null && _right == null);

            if (_parent._left == this)
            {
                _parent._left = null;
            }
            else
            {
                Debug.Assert(_parent._right == this);
                _parent._right = null;
            }

            _parent = null;
            RemoveList();
            _tree = null;
        }
        /// <summary>
        /// Adds the specified <see cref="BraidedTreeNode{TKey, TValue}"/> to the tree structure, as
        /// a leaf node of the current instance.</summary>
        /// <param name="node">
        /// The <see cref="BraidedTreeNode{TKey, TValue}"/> to add.</param>
        /// <param name="isRight">
        /// <c>true</c> to add <paramref name="node"/> as the <see cref="Right"/> descendant;
        /// <c>false</c> to add <paramref name="node"/> as the <see cref="Left"/> descendant. The
        /// corresponding property must be a null reference.</param>
        /// <remarks>
        /// <b>AddTree</b> also sets the <see cref="Parent"/> reference of the specified <paramref
        /// name="node"/> to the current instance, and updates the chains of <see cref="Previous"/>
        /// and <see cref="Next"/> references to include <paramref name="node"/>.</remarks>

        internal void AddTree(BraidedTreeNode <TKey, TValue> node, bool isRight)
        {
            Debug.Assert(node._parent == null);
            node._parent = this;

            if (isRight)
            {
                Debug.Assert(_right == null);
                _right = node;
                AddList(node);
            }
            else
            {
                Debug.Assert(_left == null);
                _left = node;
                _previous.AddList(node);
            }
        }
        /// <summary>
        /// Rotates the <see cref="BraidedTreeNode{TKey, TValue}"/> to the right within the tree
        /// structure.</summary>
        /// <remarks>
        /// <b>RotateRight</b> implements the <c>rotateRight</c> algorithm by Michael J. Laszlo,
        /// <em>Computational Geometry and Computer Graphics in C++</em>, Prentice Hall 1996, p.58.
        /// </remarks>

        private void RotateRight()
        {
            BraidedTreeNode <TKey, TValue> y = this, x = y._left, p = y._parent;

            y._left = x._right;
            if (y._left != null)
            {
                y._left._parent = y;
            }
            if (p._right == y)
            {
                p._right = x;
            }
            else
            {
                p._left = x;
            }

            x._parent = p;
            x._right  = y;
            y._parent = x;
        }
        /// <summary>
        /// Rotates the <see cref="BraidedTreeNode{TKey, TValue}"/> to the left within the tree
        /// structure.</summary>
        /// <remarks>
        /// <b>RotateLeft</b> implements the <c>rotateLeft</c> algorithm by Michael J. Laszlo,
        /// <em>Computational Geometry and Computer Graphics in C++</em>, Prentice Hall 1996, p.58.
        /// </remarks>

        private void RotateLeft()
        {
            BraidedTreeNode <TKey, TValue> x = this, y = x._right, p = x._parent;

            x._right = y._left;
            if (x._right != null)
            {
                x._right._parent = x;
            }
            if (p._left == x)
            {
                p._left = y;
            }
            else
            {
                p._right = y;
            }

            y._parent = p;
            y._left   = x;
            x._parent = y;
        }
        /// <summary>
        /// Clears all references to other <see cref="BraidedTreeNode{TKey, TValue}"/> instances.
        /// </summary>
        /// <remarks>
        /// <b>Clear</b> resets the <see cref="Previous"/> and <see cref="Next"/> properties to the
        /// current instance, and the <see cref="Left"/>, <see cref="Right"/> and <see
        /// cref="Parent"/>, properties to null references. Other properties remain unchanged,
        /// including the <see cref="Tree"/> property.</remarks>

        internal void Clear()
        {
            _next = _previous = this;
            _left = _right = _parent = null;
        }
        /// <summary>
        /// Removes the <see cref="BraidedTreeNode{TKey, TValue}"/> from the linked list.</summary>
        /// <remarks>
        /// <b>RemoveList</b> updates the chains of <see cref="Previous"/> and <see cref="Next"/>
        /// references to exclude the current instance.</remarks>

        private void RemoveList()
        {
            _previous._next = _next;
            _next._previous = _previous;
            _next           = _previous = this;
        }