sandbox: increase number of nodes in btree test
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
#include <socks/memblock.h>
|
#include <socks/memblock.h>
|
||||||
#include <socks/vm.h>
|
#include <socks/vm.h>
|
||||||
|
|
||||||
#define NR_BTREE_NODES 32
|
#define NR_BTREE_NODES 1024
|
||||||
|
|
||||||
/* we're working with 512MiB of simulated system RAM */
|
/* we're working with 512MiB of simulated system RAM */
|
||||||
#define MEMORY_SIZE_MB 512
|
#define MEMORY_SIZE_MB 512
|
||||||
@@ -169,7 +169,7 @@ void btree_print(btree_node_t *node, int depth)
|
|||||||
} else {
|
} else {
|
||||||
printf("? ");
|
printf("? ");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%llu (h:%d)\n", node->b_key, node->b_height);
|
printf("%llu (h:%d)\n", node->b_key, node->b_height);
|
||||||
@@ -230,13 +230,32 @@ static int btree_avl_validate(btree_node_t *x)
|
|||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static btree_key_t alloc_unique_key(btree_node_t *nodes, size_t count)
|
||||||
|
{
|
||||||
|
while (1) {
|
||||||
|
btree_key_t k = (rand() % 8192) + 1;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; i++) {
|
||||||
|
if (nodes[i].b_key == k) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return k;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (btree_key_t)-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int btree_test(void)
|
static int btree_test(void)
|
||||||
{
|
{
|
||||||
btree_t tree = {};
|
btree_t tree = {};
|
||||||
btree_node_t *nodes = calloc(NR_BTREE_NODES, sizeof *nodes);
|
btree_node_t *nodes = calloc(NR_BTREE_NODES, sizeof *nodes);
|
||||||
|
|
||||||
for (int i = 0; i < NR_BTREE_NODES; i++) {
|
for (int i = 0; i < NR_BTREE_NODES; i++) {
|
||||||
nodes[i].b_key = (rand() % 128) + 1;
|
nodes[i].b_key = alloc_unique_key(nodes, i);
|
||||||
printf(" - node %d: %llu\n", i, nodes[i].b_key);
|
printf(" - node %d: %llu\n", i, nodes[i].b_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user