4 BTree::BTree (const char *name, unsigned int block_size, bool create_new_file)
9 fp = fopen (name, "wb");
11 /* TODO : mandar una exception ? */
15 /* Nombre de archivo */
18 /* Inicializo el header */
19 header.block_size = block_size;
22 /* Creo el primer bloque vacio */
23 node = new uchar[block_size];
24 ReadNodoHeader (node, &nh);
26 nh.free_space = block_size - sizeof (BTreeNodeHeader);
28 WriteNodoHeader (node, &nh);
29 write_block (node, 0);
39 void BTree::write_tree_header ()
41 fseek (fp, 0L, SEEK_SET);
42 fwrite (&header, 1, sizeof (BTreeFileHeader), fp);
45 void BTree::write_block (uchar *block, uint num)
47 fseek (fp, num*header.block_size + sizeof (BTreeFileHeader), SEEK_SET);
48 fwrite (block, 1, header.block_size, fp);
51 void BTree::AddKey () {}
52 void BTree::DelKey () {}
54 void BTree::ReadNodoHeader (uchar *node, BTreeNodeHeader *header)
56 memcpy (header, node, sizeof (BTreeNodeHeader));
59 void BTree::WriteNodoHeader (uchar *node, BTreeNodeHeader *header)
61 memcpy (node, header, sizeof (BTreeNodeHeader));