fn fixup(mut root: Box<Node>) -> Box<Node> {
        // Calculate the balance factor and check if we need rebalancing.
        let balance_factor = root.balance_factor();
        if balance_factor == 2 {
            // Subtree is left heavy.

            // Must exist, otherwise this balance factor is impossible.
            let left = root.left.take().expect("left heavy");
            if left.balance_factor() == -1 {
                root.left = Some(Self::rotate_left(left));
            } else {
                root.left = Some(left);
            }

            Self::rotate_right(root)
        } else if balance_factor == -2 {
            // Subtree is right heavy.

            // Must exist, otherwise this balance factor is impossible.
            let right = root.right.take().expect("right heavy");
            if right.balance_factor() == 1 {
                root.right = Some(Self::rotate_right(right));
            } else {
                root.right = Some(right);
            }

            Self::rotate_left(root)
        } else {
            // Fields are not updated by rotations, update it manually here.
            root.update_fields();
            root
        }
    }
/// Fixes the AVL rotations. Returns the new root.
Fixes the AVL rotations. Returns the new root.
Fixes the AVL rotations . Returns the new root .
fn fixup(mut root: Box<Node>) -> Box<Node> {
        // Calculate the balance factor and check if we need rebalancing.
        let balance_factor = root.balance_factor();
        if balance_factor == 2 {
            // Subtree is left heavy.
            // Must exist, otherwise this balance factor is impossible.
            let left = root.left.take().expect("left heavy");
            if left.balance_factor() == -1 {
                root.left = Some(Self::rotate_left(left));
            } else {
                root.left = Some(left);
            }
            Self::rotate_right(root)
        } else if balance_factor == -2 {
            // Subtree is right heavy.
            // Must exist, otherwise this balance factor is impossible.
            let right = root.right.take().expect("right heavy");
            if right.balance_factor() == 1 {
                root.right = Some(Self::rotate_right(right));
            } else {
                root.right = Some(right);
            }
            Self::rotate_left(root)
        } else {
            // Fields are not updated by rotations, update it manually here.
            root.update_fields();
            root
        }
    }
fn fixup ( mut root : Box < Node > ) -> Box < Node > { // Calculate the balance factor and check if we need rebalancing. let balance_factor = root . balance_factor ( ) ; if balance_factor == 2 { // Subtree is left heavy. // Must exist, otherwise this balance factor is impossible. let left = root . left . take ( ) . expect ( " " ) ; if left . balance_factor ( ) == - 1 { root . left = Some ( Self :: rotate_left ( left ) ) ; } else { root . left = Some ( left ) ; } Self :: rotate_right ( root ) } else if balance_factor == - 2 { // Subtree is right heavy. // Must exist, otherwise this balance factor is impossible. let right = root . right . take ( ) . expect ( " " ) ; if right . balance_factor ( ) == 1 { root . right = Some ( Self :: rotate_right ( right ) ) ; } else { root . right = Some ( right ) ; } Self :: rotate_left ( root ) } else { // Fields are not updated by rotations, update it manually here. root . update_fields ( ) ; root } }
Fixes the AVL rotations.
Fixes the AVL rotations .
root
Box<Node>
root
Box<Node>