Beispiel #1
0
/* Inserts a new node (leaf or internal node) into the B+ tree.
 * Returns the root of the tree after insertion.
 */
node * insert_into_parent(node * root, node * left, int key, node * right) {
 
    int left_index;
    node * parent;
 
    parent = left->parent;
 
    /* Case: new root. */
 
    if (parent == NULL)
        return insert_into_new_root(left, key, right);
 
    /* Case: leaf or node. (Remainder of
     * function body.)
     */
 
    /* Find the parent's pointer to the left
     * node.
     */
 
    left_index = get_left_index(parent, left);
 
 
    /* Simple case: the new key fits into the node.
     */
 
    if (parent->num_keys < order - 1)
        return insert_into_node(root, parent, left_index, key, right);
 
    /* Harder case:  split a node in order
     * to preserve the B+ tree properties.
     */
 
    return insert_into_node_after_splitting(root, parent, left_index, key, right);
}
Beispiel #2
0
node *insert_into_parent(node *root, node *left, node *right, char *key)
{
    node *parent;
    int index, i;
    parent = left->parent;

    if (parent == NULL){
        return make_new_root(left, right, key);
    }

    for (index = 0; index < parent->num_keys && parent->pointers[index] != left; index++);
        ;
    if (parent->num_keys < size - 1){
        insert_into_node(parent, right, index, key);
        return root;  // the root remains unchanged
    }
    return insert_into_node_after_splitting(root, parent, right, index, key);
}