pub fn insert_as_internal(mut self, key: K, value: V, right: Node<K, V>)
            -> InsertionResult<K, V> {
        if !self.node.is_full() {
            // The element can fit, just insert it
            unsafe {
                self.node.insert_kv(self.index, key, value);
                self.node.insert_edge(self.index + 1, right); // +1 to insert to the right
            }
            Fit
        } else {
            // The element can't fit, this node is full. Split it into two nodes.
            let (new_key, new_val, mut new_right) = self.node.split();
            let left_len = self.node.len();

            if self.index <= left_len {
                unsafe {
                    self.node.insert_kv(self.index, key, value);
                    self.node.insert_edge(self.index + 1, right); // +1 to insert to the right
                }
            } else {
                unsafe {
                    // The -1 here is for the same reason as in insert_as_internal - because we
                    // split, there are actually left_len + 1 k/v pairs before the right node, with
                    // the extra 1 being put in the parent.
                    new_right.insert_kv(self.index - left_len - 1, key, value);
                    new_right.insert_edge(self.index - left_len, right);
                }
            }

            Split(new_key, new_val, new_right)
        }
    }
/// Tries to insert this key-value pair at the given index in this internal node
/// If the node is full, we have to split it.
Tries to insert this key-value pair at the given index in this internal node
If the node is full, we have to split it.
Tries to insert this key - value pair at the given index in this internal node If the node is full we have to split it .
pub fn insert_as_internal(mut self, key: K, value: V, right: Node<K, V>)
            -> InsertionResult<K, V> {
        if !self.node.is_full() {
            // The element can fit, just insert it
            unsafe {
                self.node.insert_kv(self.index, key, value);
                self.node.insert_edge(self.index + 1, right); // +1 to insert to the right
            }
            Fit
        } else {
            // The element can't fit, this node is full. Split it into two nodes.
            let (new_key, new_val, mut new_right) = self.node.split();
            let left_len = self.node.len();
            if self.index <= left_len {
                unsafe {
                    self.node.insert_kv(self.index, key, value);
                    self.node.insert_edge(self.index + 1, right); // +1 to insert to the right
                }
            } else {
                unsafe {
                    // The -1 here is for the same reason as in insert_as_internal - because we
                    // split, there are actually left_len + 1 k/v pairs before the right node, with
                    // the extra 1 being put in the parent.
                    new_right.insert_kv(self.index - left_len - 1, key, value);
                    new_right.insert_edge(self.index - left_len, right);
                }
            }
            Split(new_key, new_val, new_right)
        }
    }
pub fn insert_as_internal ( mut self , key : K , value : V , right : Node < K , V > ) -> InsertionResult < K , V > { if ! self . node . is_full ( ) { // The element can fit, just insert it unsafe { self . node . insert_kv ( self . index , key , value ) ; self . node . insert_edge ( self . index + 1 , right ) ; // +1 to insert to the right } Fit } else { // The element can't fit, this node is full. Split it into two nodes. let ( new_key , new_val , mut new_right ) = self . node . split ( ) ; let left_len = self . node . len ( ) ; if self . index <= left_len { unsafe { self . node . insert_kv ( self . index , key , value ) ; self . node . insert_edge ( self . index + 1 , right ) ; // +1 to insert to the right } } else { unsafe { // The -1 here is for the same reason as in insert_as_internal - because we // split, there are actually left_len + 1 k/v pairs before the right node, with // the extra 1 being put in the parent. new_right . insert_kv ( self . index - left_len - 1 , key , value ) ; new_right . insert_edge ( self . index - left_len , right ) ; } } Split ( new_key , new_val , new_right ) } }
Tries to insert this key-value pair at the given index in this internal node
If the node is full, we have to split it.
Tries to insert this key - value pair at the given index in this internal node If the node is full we have to split it .
mut self
key
K
value
V
right
Node<K, V>