Changes in kernel/generic/src/adt/btree.c [1ab4aca:8b3bff5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/adt/btree.c
r1ab4aca r8b3bff5 38 38 * 39 39 * The B+tree has the following properties: 40 * @li it is a bal anced 3-4-5 tree (i.e. BTREE_M = 5)40 * @li it is a ballanced 3-4-5 tree (i.e. BTREE_M = 5) 41 41 * @li values (i.e. pointers to values) are stored only in leaves 42 42 * @li leaves are linked in a list 43 43 * 44 * Be careful when using these trees. They need to allocate44 * Be carefull when using these trees. They need to allocate 45 45 * and deallocate memory for their index nodes and as such 46 46 * can sleep. … … 108 108 void btree_create(btree_t *t) 109 109 { 110 list_initialize(&t->leaf_ list);110 list_initialize(&t->leaf_head); 111 111 t->root = (btree_node_t *) slab_alloc(btree_node_slab, 0); 112 112 node_initialize(t->root); 113 list_append(&t->root->leaf_link, &t->leaf_ list);113 list_append(&t->root->leaf_link, &t->leaf_head); 114 114 } 115 115 … … 146 146 * also makes use of this feature. 147 147 * 148 * @param node B-tree node into w hich the new key is to be inserted.148 * @param node B-tree node into wich the new key is to be inserted. 149 149 * @param key The key to be inserted. 150 150 * @param value Pointer to value to be inserted. … … 270 270 * This feature is used during insert by right rotation. 271 271 * 272 * @param node B-tree node into w hich the new key is to be inserted.272 * @param node B-tree node into wich the new key is to be inserted. 273 273 * @param key The key to be inserted. 274 274 * @param value Pointer to value to be inserted. … … 463 463 if (rnode->keys < BTREE_MAX_KEYS) { 464 464 /* 465 * The rota tion can be done. The right sibling has free space.465 * The rotaion can be done. The right sibling has free space. 466 466 */ 467 467 node_insert_key_and_rsubtree(node, inskey, insvalue, rsubtree); … … 484 484 * the median will be copied there. 485 485 * 486 * @param node B-tree node w hich is going to be split.486 * @param node B-tree node wich is going to be split. 487 487 * @param key The key to be inserted. 488 488 * @param value Pointer to the value to be inserted. … … 562 562 if (node->keys < BTREE_MAX_KEYS) { 563 563 /* 564 * Node con tains enough space, the key can be stored immediately.564 * Node conatins enough space, the key can be stored immediately. 565 565 */ 566 566 node_insert_key_and_rsubtree(node, key, value, rsubtree); … … 588 588 589 589 if (LEAF_NODE(node)) { 590 list_ insert_after(&rnode->leaf_link, &node->leaf_link);590 list_prepend(&rnode->leaf_link, &node->leaf_link); 591 591 } 592 592 … … 806 806 807 807 /* 808 * The key can be immediatel y removed.808 * The key can be immediatelly removed. 809 809 * 810 810 * Note that the right subtree is removed because when … … 953 953 ASSERT(LEAF_NODE(node)); 954 954 955 if (node->leaf_link.prev != &t->leaf_ list.head)955 if (node->leaf_link.prev != &t->leaf_head) 956 956 return list_get_instance(node->leaf_link.prev, btree_node_t, leaf_link); 957 957 else … … 972 972 ASSERT(LEAF_NODE(node)); 973 973 974 if (node->leaf_link.next != &t->leaf_ list.head)974 if (node->leaf_link.next != &t->leaf_head) 975 975 return list_get_instance(node->leaf_link.next, btree_node_t, leaf_link); 976 976 else … … 987 987 size_t i; 988 988 int depth = t->root->depth; 989 li st_t list;989 link_t head, *cur; 990 990 991 991 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); 994 994 995 995 /* … … 997 997 * Levels are distinguished from one another by node->depth. 998 998 */ 999 while (!list_empty(& list)) {999 while (!list_empty(&head)) { 1000 1000 link_t *hlp; 1001 1001 btree_node_t *node; 1002 1002 1003 hlp = list_first(&list);1004 ASSERT(hlp != NULL);1003 hlp = head.next; 1004 ASSERT(hlp != &head); 1005 1005 node = list_get_instance(hlp, btree_node_t, bfs_link); 1006 1006 list_remove(hlp); … … 1018 1018 printf("%" PRIu64 "%s", node->key[i], i < node->keys - 1 ? "," : ""); 1019 1019 if (node->depth && node->subtree[i]) { 1020 list_append(&node->subtree[i]->bfs_link, & list);1020 list_append(&node->subtree[i]->bfs_link, &head); 1021 1021 } 1022 1022 } 1023 1023 1024 1024 if (node->depth && node->subtree[i]) 1025 list_append(&node->subtree[i]->bfs_link, & list);1025 list_append(&node->subtree[i]->bfs_link, &head); 1026 1026 1027 1027 printf(")"); … … 1031 1031 1032 1032 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) { 1034 1034 btree_node_t *node; 1035 1035
Note:
See TracChangeset
for help on using the changeset viewer.