sandbox: btree: deletion fixup bugfix
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include <socks/memblock.h>
|
||||
#include <socks/vm.h>
|
||||
|
||||
#define NR_BTREE_NODES 13
|
||||
#define NR_BTREE_NODES 32
|
||||
|
||||
/* we're working with 512MiB of simulated system RAM */
|
||||
#define MEMORY_SIZE_MB 512
|
||||
@@ -130,10 +130,28 @@ static int memory_test(void)
|
||||
|
||||
void btree_print(btree_node_t *node, int depth)
|
||||
{
|
||||
if (depth > 10) {
|
||||
for (int i = 0; i < depth; i++) {
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
|
||||
printf("OVERFLOW\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node->b_parent && node != node->b_parent->b_left && node != node->b_parent->b_right) {
|
||||
for (int i = 0; i < depth; i++) {
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
|
||||
printf("BAD PARENT [%llu]\n", node->b_key);
|
||||
return;
|
||||
}
|
||||
|
||||
if (node) {
|
||||
btree_print(node->b_right, depth + 1);
|
||||
}
|
||||
@@ -146,9 +164,12 @@ void btree_print(btree_node_t *node, int depth)
|
||||
if (node->b_parent) {
|
||||
if (node == node->b_parent->b_left) {
|
||||
printf("\\ ");
|
||||
} else {
|
||||
} else if (node == node->b_parent->b_right) {
|
||||
printf("/ ");
|
||||
} else {
|
||||
printf("? ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printf("%llu (h:%d)\n", node->b_key, node->b_height);
|
||||
@@ -172,7 +193,7 @@ static int btree_avl_validate(btree_node_t *x)
|
||||
}
|
||||
|
||||
if (!x->b_left && !x->b_right) {
|
||||
return 1;
|
||||
return x->b_height == 1 ? 1 : -1;
|
||||
}
|
||||
|
||||
int left = 0, right = 0;
|
||||
@@ -241,10 +262,6 @@ static int btree_test(void)
|
||||
printf("deleting node #%d: %llu\n", i, nodes[i].b_key);
|
||||
printf("#######################\n");
|
||||
|
||||
if (nodes[i].b_key == 89) {
|
||||
printf("brk\n");
|
||||
}
|
||||
|
||||
btree_delete(&tree, &nodes[i]);
|
||||
btree_print(tree.b_root, 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user