sandbox: added some AVL tree insertion stress testing
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include <socks/memblock.h>
|
||||
#include <socks/vm.h>
|
||||
|
||||
#define NR_BTREE_NODES 3
|
||||
#define NR_BTREE_NODES 4096
|
||||
|
||||
/* we're working with 512MiB of simulated system RAM */
|
||||
#define MEMORY_SIZE_MB 512
|
||||
@@ -127,7 +127,7 @@ static int memory_test(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void btree_print(btree_node_t *node, int depth)
|
||||
void btree_print(btree_node_t *node, int depth)
|
||||
{
|
||||
if (!node) {
|
||||
return;
|
||||
@@ -155,22 +155,24 @@ static void btree_print(btree_node_t *node, int depth)
|
||||
static int btree_test(void)
|
||||
{
|
||||
btree_t tree = {};
|
||||
btree_node_t nodes[] = {
|
||||
{ .b_key = 1 },
|
||||
{ .b_key = 2 },
|
||||
{ .b_key = 3 },
|
||||
{ .b_key = 4 },
|
||||
{ .b_key = 5 },
|
||||
{ .b_key = 6 },
|
||||
{ .b_key = 7 },
|
||||
};
|
||||
btree_node_t *nodes = calloc(NR_BTREE_NODES, sizeof *nodes);
|
||||
|
||||
int nr_nodes = sizeof nodes / sizeof nodes[0];
|
||||
for (int i = 0; i < nr_nodes; i++) {
|
||||
btree_insert(&tree, &nodes[i]);
|
||||
for (int i = 0; i < NR_BTREE_NODES; i++) {
|
||||
nodes[i].b_key = (rand() % 512000) + 1;
|
||||
printf(" - node %d: %llu\n", i, nodes[i].b_key);
|
||||
}
|
||||
btree_print(tree.b_root, 0);
|
||||
|
||||
for (int i = 0; i < NR_BTREE_NODES; i++) {
|
||||
printf("#######################\n");
|
||||
printf("inserting node #%d: %llu\n", i, nodes[i].b_key);
|
||||
|
||||
btree_insert(&tree, &nodes[i]);
|
||||
printf("#######################\n");
|
||||
|
||||
btree_print(tree.b_root, 0);
|
||||
}
|
||||
|
||||
#if 0
|
||||
int to_delete[] = { 3, 1, 0 };
|
||||
int nr_to_delete = sizeof to_delete / sizeof to_delete[0];
|
||||
|
||||
@@ -184,7 +186,9 @@ static int btree_test(void)
|
||||
btree_delete(&tree, &nodes[node_index]);
|
||||
btree_print(tree.b_root, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
free(nodes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user