fn ins<T: ::std::fmt::Debug, C>(tree: Child<T>, x: T, comparator: C) -> Arc<RBTreeNode<T>>
where
    T: Ord + Clone,
    C: Comparator<Item = T> + Copy,
{
    match tree {
        Some(ref t) => {
            match C::compare(&x, &t.item) {
                Ordering::Less => {
                    balance(Arc::new(RBTreeNode::new(
                        t.color,
                        Some(ins(t.left.clone(), x, comparator)),
                        t.item.clone(),
                        t.right.clone(),
                    )))
                }
                Ordering::Equal => {
                    t.clone() // duplicate
                }
                Ordering::Greater => {
                    balance(Arc::new(RBTreeNode::new(
                        t.color,
                        t.left.clone(),
                        t.item.clone(),
                        Some(ins(t.right.clone(), x, comparator)),
                    )))
                }
            }
        }
        None => Arc::new(RBTreeNode::new_red(None, x, None)),
    }
}
/// Helper function to insert an item into a red-black tree. It does
/// NOT enforce invariants in the base case (leaving that to `balance`
/// in the recursive cases), and it does not color the root of the
/// tree black.
Helper function to insert an item into a red-black tree. It does
NOT enforce invariants in the base case (leaving that to `balance`
in the recursive cases), and it does not color the root of the
tree black.
Helper function to insert an item into a red - black tree . It does NOT enforce invariants in the base case ( leaving that to ` balance ` in the recursive cases ) and it does not color the root of the tree black .
fn ins<T: ::std::fmt::Debug, C>(tree: Child<T>, x: T, comparator: C) -> Arc<RBTreeNode<T>>
where
    T: Ord + Clone,
    C: Comparator<Item = T> + Copy,
{
    match tree {
        Some(ref t) => {
            match C::compare(&x, &t.item) {
                Ordering::Less => {
                    balance(Arc::new(RBTreeNode::new(
                        t.color,
                        Some(ins(t.left.clone(), x, comparator)),
                        t.item.clone(),
                        t.right.clone(),
                    )))
                }
                Ordering::Equal => {
                    t.clone() // duplicate
                }
                Ordering::Greater => {
                    balance(Arc::new(RBTreeNode::new(
                        t.color,
                        t.left.clone(),
                        t.item.clone(),
                        Some(ins(t.right.clone(), x, comparator)),
                    )))
                }
            }
        }
        None => Arc::new(RBTreeNode::new_red(None, x, None)),
    }
}
fn ins < T : :: std :: fmt :: Debug , C > ( tree : Child < T > , x : T , comparator : C ) -> Arc < RBTreeNode < T > > where T : Ord + Clone , C : Comparator < Item = T > + Copy , { match tree { Some ( ref t ) => { match C :: compare ( & x , & t . item ) { Ordering :: Less => { balance ( Arc :: new ( RBTreeNode :: new ( t . color , Some ( ins ( t . left . clone ( ) , x , comparator ) ) , t . item . clone ( ) , t . right . clone ( ) , ) ) ) } Ordering :: Equal => { t . clone ( ) // duplicate } Ordering :: Greater => { balance ( Arc :: new ( RBTreeNode :: new ( t . color , t . left . clone ( ) , t . item . clone ( ) , Some ( ins ( t . right . clone ( ) , x , comparator ) ) , ) ) ) } } } None => Arc :: new ( RBTreeNode :: new_red ( None , x , None ) ) , } }
Helper function to insert an item into a red-black tree.
Helper function to insert an item into a red - black tree .
tree
Child<T>
x
T
comparator
C
tree
Child<T>
x
T
comparator
C