Changeset 296cc1b in mainline


Ignore:
Timestamp:
2006-03-30T18:39:21Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ca687ad
Parents:
ff75d34
Message:

Change B+-tree from 2-3-4 tree to 2-3-4-5 tree by adding space for the fourth key.
This should make key removal easier.

Location:
generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • generic/include/adt/btree.h

    rff75d34 r296cc1b  
    3434#include <adt/list.h>
    3535
    36 #define BTREE_M         4
     36#define BTREE_M         5
    3737#define BTREE_MAX_KEYS  (BTREE_M - 1)
    3838
     
    5353        /**
    5454         * Pointers to descendants of this node sorted according to the key array.
    55          * subtree[0] points to subtree with keys lesser than or equal to key[0].
    56          * subtree[1] points to subtree with keys greater than key[0] and lesser than or equal to key[1].
     55         * subtree[0] points to subtree with keys lesser than to key[0].
     56         * subtree[1] points to subtree with keys greater than or equal to key[0] and lesser than key[1].
    5757         * ...
    5858         * There is room for storing a subtree pointer for the extra key.
     
    8181
    8282extern void btree_insert(btree_t *t, __native key, void *value, btree_node_t *leaf_node);
    83 extern void btree_remove(btree_t *t, __native key);
     83extern void btree_remove(btree_t *t, __native key, btree_node_t *leaf_node);
    8484extern void *btree_search(btree_t *t, __native key, btree_node_t **leaf_node);
    8585
  • generic/src/adt/btree.c

    rff75d34 r296cc1b  
    2929/*
    3030 * This B-tree has the following properties:
    31  * - it is a ballanced 2-3-4 tree (i.e. BTREE_M = 4)
     31 * - it is a ballanced 2-3-4-5 tree (i.e. BTREE_M = 5)
    3232 * - values (i.e. pointers to values) are stored only in leaves
    3333 * - leaves are linked in a list
     
    6161#define INDEX_NODE(n)           ((n)->subtree[0] != NULL)
    6262#define LEAF_NODE(n)            ((n)->subtree[0] == NULL)
     63
     64#define FILL_FACTOR             ((BTREE_M-1)/2)
    6365
    6466#define MEDIAN_LOW_INDEX(n)     (((n)->keys-1)/2)
     
    172174}
    173175
    174 /* TODO */
    175 void btree_remove(btree_t *t, __native key)
    176 {
     176/** Remove B-tree node.
     177 *
     178 * @param B-tree.
     179 * @param key Key to be removed from the B-tree along with its associated value.
     180 * @param leaf_node If not NULL, pointer to the leaf node where the key is found.
     181 */
     182void btree_remove(btree_t *t, __native key, btree_node_t *leaf_node)
     183{
     184        btree_node_t *lnode;
     185       
     186        lnode = leaf_node;
     187        if (!lnode) {
     188                if (!btree_search(t, key, &lnode)) {
     189                        panic("B-tree %P does not contain key %d\n", t, key);
     190                }
     191        }
     192       
     193        /* TODO */
     194
    177195}
    178196
Note: See TracChangeset for help on using the changeset viewer.