Пример #1
0
        /// <summary>
        /// AVL rotate double-right operation.
        /// </summary>
        /// <param name="tree">The tree.</param>
        /// <returns>The rotated tree.</returns>
        private static SortedInt32KeyNode <TValue> DoubleRight(SortedInt32KeyNode <TValue> tree)
        {
            Requires.NotNull(tree, "tree");
            Debug.Assert(!tree.IsEmpty);

            if (tree._left.IsEmpty)
            {
                return(tree);
            }

            SortedInt32KeyNode <TValue> rotatedLeftChild = tree.Mutate(left: RotateLeft(tree._left));

            return(RotateRight(rotatedLeftChild));
        }
Пример #2
0
        /// <summary>
        /// AVL rotate right operation.
        /// </summary>
        /// <param name="tree">The tree.</param>
        /// <returns>The rotated tree.</returns>
        private static SortedInt32KeyNode <TValue> RotateRight(SortedInt32KeyNode <TValue> tree)
        {
            Requires.NotNull(tree, nameof(tree));
            Debug.Assert(!tree.IsEmpty);

            if (tree._left.IsEmpty)
            {
                return(tree);
            }

            var left = tree._left;

            return(left.Mutate(right: tree.Mutate(left: left._right)));
        }
Пример #3
0
        /// <summary>
        /// AVL rotate left operation.
        /// </summary>
        /// <param name="tree">The tree.</param>
        /// <returns>The rotated tree.</returns>
        private static SortedInt32KeyNode <TValue> RotateLeft(SortedInt32KeyNode <TValue> tree)
        {
            Requires.NotNull(tree, "tree");
            Debug.Assert(!tree.IsEmpty);

            if (tree._right.IsEmpty)
            {
                return(tree);
            }

            var right = tree._right;

            return(right.Mutate(left: tree.Mutate(right: right._left)));
        }