fn remove_helper(mut root: Box<Node>, interval_start: usize) -> (TreeNode, Option<usize>) {
        match interval_start.cmp(&root.interval_start) {
            Ordering::Less => {
                if let Some(left) = root.left.take() {
                    let (left, result) = Self::remove_helper(left, interval_start);
                    root.left = left;
                    return (Some(Node::fixup(root)), result);
                }
            }
            Ordering::Greater => {
                if let Some(right) = root.right.take() {
                    let (right, result) = Self::remove_helper(right, interval_start);
                    root.right = right;
                    return (Some(Node::fixup(root)), result);
                }
            }
            Ordering::Equal => {
                let len = root.interval_len;

                let node = if root.left.is_none() && root.right.is_none() {
                    None
                } else if root.left.is_none() {
                    root.right.take()
                } else if root.right.is_none() {
                    root.left.take()
                } else {
                    let (remaining, mut replacement) = Self::remove_min(root.right.take().unwrap());
                    replacement.left = root.left.take();
                    replacement.right = remaining;
                    Some(Node::fixup(replacement))
                };

                return (node, Some(len));
            }
        }

        (Some(root), None)
    }
/// Recursive remove procedure, returns new root and removed length.
Recursive remove procedure, returns new root and removed length.
Recursive remove procedure returns new root and removed length .
fn remove_helper(mut root: Box<Node>, interval_start: usize) -> (TreeNode, Option<usize>) {
        match interval_start.cmp(&root.interval_start) {
            Ordering::Less => {
                if let Some(left) = root.left.take() {
                    let (left, result) = Self::remove_helper(left, interval_start);
                    root.left = left;
                    return (Some(Node::fixup(root)), result);
                }
            }
            Ordering::Greater => {
                if let Some(right) = root.right.take() {
                    let (right, result) = Self::remove_helper(right, interval_start);
                    root.right = right;
                    return (Some(Node::fixup(root)), result);
                }
            }
            Ordering::Equal => {
                let len = root.interval_len;
                let node = if root.left.is_none() && root.right.is_none() {
                    None
                } else if root.left.is_none() {
                    root.right.take()
                } else if root.right.is_none() {
                    root.left.take()
                } else {
                    let (remaining, mut replacement) = Self::remove_min(root.right.take().unwrap());
                    replacement.left = root.left.take();
                    replacement.right = remaining;
                    Some(Node::fixup(replacement))
                };
                return (node, Some(len));
            }
        }
        (Some(root), None)
    }
fn remove_helper ( mut root : Box < Node > , interval_start : usize ) -> ( TreeNode , Option < usize > ) { match interval_start . cmp ( & root . interval_start ) { Ordering :: Less => { if let Some ( left ) = root . left . take ( ) { let ( left , result ) = Self :: remove_helper ( left , interval_start ) ; root . left = left ; return ( Some ( Node :: fixup ( root ) ) , result ) ; } } Ordering :: Greater => { if let Some ( right ) = root . right . take ( ) { let ( right , result ) = Self :: remove_helper ( right , interval_start ) ; root . right = right ; return ( Some ( Node :: fixup ( root ) ) , result ) ; } } Ordering :: Equal => { let len = root . interval_len ; let node = if root . left . is_none ( ) && root . right . is_none ( ) { None } else if root . left . is_none ( ) { root . right . take ( ) } else if root . right . is_none ( ) { root . left . take ( ) } else { let ( remaining , mut replacement ) = Self :: remove_min ( root . right . take ( ) . unwrap ( ) ) ; replacement . left = root . left . take ( ) ; replacement . right = remaining ; Some ( Node :: fixup ( replacement ) ) } ; return ( node , Some ( len ) ) ; } } ( Some ( root ) , None ) }
Recursive remove procedure, returns new root and removed length.
Recursive remove procedure returns new root and removed length .
root
Box<Node>
interval_start
usize
root
Box<Node>
interval_start
usize