BTREE CREATION

I am trying to create a B-tree, but actually the problem with the B-Tree creation is that I need to store it on the hard disk and I also need to allocate physical address from the hard disk to each node. So can anyone help how to do that...
The simplest solution: place all nodes in an array, and instead of using pointers for left/right children, use offsets within this array.

1
2
3
4
5
6
7
8
9
10
11
12
struct node_t
{
   int left;
   int right;
};

std::vector<node_t> tree;

node_t * left(node_t * node)
{
   return &tree[node->left];
}


The whole array can be simply written to a disk file without any processing, as it does not contain any pointers.
Topic archived. No new replies allowed.