Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/adt/btree.c

    r1ab4aca r8b3bff5  
    3838 *
    3939 * The B+tree has the following properties:
    40  * @li it is a balanced 3-4-5 tree (i.e. BTREE_M = 5)
     40 * @li it is a ballanced 3-4-5 tree (i.e. BTREE_M = 5)
    4141 * @li values (i.e. pointers to values) are stored only in leaves
    4242 * @li leaves are linked in a list
    4343 *
    44  * Be careful when using these trees. They need to allocate
     44 * Be carefull when using these trees. They need to allocate
    4545 * and deallocate memory for their index nodes and as such
    4646 * can sleep.
     
    108108void btree_create(btree_t *t)
    109109{
    110         list_initialize(&t->leaf_list);
     110        list_initialize(&t->leaf_head);
    111111        t->root = (btree_node_t *) slab_alloc(btree_node_slab, 0);
    112112        node_initialize(t->root);
    113         list_append(&t->root->leaf_link, &t->leaf_list);
     113        list_append(&t->root->leaf_link, &t->leaf_head);
    114114}
    115115
     
    146146 * also makes use of this feature.
    147147 *
    148  * @param node     B-tree node into which the new key is to be inserted.
     148 * @param node     B-tree node into wich the new key is to be inserted.
    149149 * @param key      The key to be inserted.
    150150 * @param value    Pointer to value to be inserted.
     
    270270 * This feature is used during insert by right rotation.
    271271 *
    272  * @param node     B-tree node into which the new key is to be inserted.
     272 * @param node     B-tree node into wich the new key is to be inserted.
    273273 * @param key      The key to be inserted.
    274274 * @param value    Pointer to value to be inserted.
     
    463463        if (rnode->keys < BTREE_MAX_KEYS) {
    464464                /*
    465                  * The rotation can be done. The right sibling has free space.
     465                 * The rotaion can be done. The right sibling has free space.
    466466                 */
    467467                node_insert_key_and_rsubtree(node, inskey, insvalue, rsubtree);
     
    484484 * the median will be copied there.
    485485 *
    486  * @param node     B-tree node which is going to be split.
     486 * @param node     B-tree node wich is going to be split.
    487487 * @param key      The key to be inserted.
    488488 * @param value    Pointer to the value to be inserted.
     
    562562        if (node->keys < BTREE_MAX_KEYS) {
    563563                /*
    564                  * Node contains enough space, the key can be stored immediately.
     564                 * Node conatins enough space, the key can be stored immediately.
    565565                 */
    566566                node_insert_key_and_rsubtree(node, key, value, rsubtree);
     
    588588               
    589589                if (LEAF_NODE(node)) {
    590                         list_insert_after(&rnode->leaf_link, &node->leaf_link);
     590                        list_prepend(&rnode->leaf_link, &node->leaf_link);
    591591                }
    592592               
     
    806806               
    807807                /*
    808                  * The key can be immediately removed.
     808                 * The key can be immediatelly removed.
    809809                 *
    810810                 * Note that the right subtree is removed because when
     
    953953        ASSERT(LEAF_NODE(node));
    954954       
    955         if (node->leaf_link.prev != &t->leaf_list.head)
     955        if (node->leaf_link.prev != &t->leaf_head)
    956956                return list_get_instance(node->leaf_link.prev, btree_node_t, leaf_link);
    957957        else
     
    972972        ASSERT(LEAF_NODE(node));
    973973       
    974         if (node->leaf_link.next != &t->leaf_list.head)
     974        if (node->leaf_link.next != &t->leaf_head)
    975975                return list_get_instance(node->leaf_link.next, btree_node_t, leaf_link);
    976976        else
     
    987987        size_t i;
    988988        int depth = t->root->depth;
    989         list_t list;
     989        link_t head, *cur;
    990990       
    991991        printf("Printing B-tree:\n");
    992         list_initialize(&list);
    993         list_append(&t->root->bfs_link, &list);
     992        list_initialize(&head);
     993        list_append(&t->root->bfs_link, &head);
    994994       
    995995        /*
     
    997997         * Levels are distinguished from one another by node->depth.
    998998         */
    999         while (!list_empty(&list)) {
     999        while (!list_empty(&head)) {
    10001000                link_t *hlp;
    10011001                btree_node_t *node;
    10021002               
    1003                 hlp = list_first(&list);
    1004                 ASSERT(hlp != NULL);
     1003                hlp = head.next;
     1004                ASSERT(hlp != &head);
    10051005                node = list_get_instance(hlp, btree_node_t, bfs_link);
    10061006                list_remove(hlp);
     
    10181018                        printf("%" PRIu64 "%s", node->key[i], i < node->keys - 1 ? "," : "");
    10191019                        if (node->depth && node->subtree[i]) {
    1020                                 list_append(&node->subtree[i]->bfs_link, &list);
     1020                                list_append(&node->subtree[i]->bfs_link, &head);
    10211021                        }
    10221022                }
    10231023               
    10241024                if (node->depth && node->subtree[i])
    1025                         list_append(&node->subtree[i]->bfs_link, &list);
     1025                        list_append(&node->subtree[i]->bfs_link, &head);
    10261026               
    10271027                printf(")");
     
    10311031       
    10321032        printf("Printing list of leaves:\n");
    1033         list_foreach(t->leaf_list, cur) {
     1033        for (cur = t->leaf_head.next; cur != &t->leaf_head; cur = cur->next) {
    10341034                btree_node_t *node;
    10351035               
Note: See TracChangeset for help on using the changeset viewer.