/* Inicializo el header */
header.block_size = block_size;
- write_tree_header ();
+ WriteFileHeader ();
/* Creo el primer bloque vacio */
node = new uchar[block_size];
nh.free_space = block_size - sizeof (BTreeNodeHeader);
nh.item_count = 0;
WriteNodoHeader (node, &nh);
- write_block (node, 0);
+ WriteBlock (node, 0);
delete [] node;
}
fclose (fp);
}
-void BTree::write_tree_header ()
+void BTree::WriteFileHeader ()
{
fseek (fp, 0L, SEEK_SET);
fwrite (&header, 1, sizeof (BTreeFileHeader), fp);
}
-void BTree::write_block (uchar *block, uint num)
+void BTree::WriteBlock (uchar *block, uint num)
{
fseek (fp, num*header.block_size + sizeof (BTreeFileHeader), SEEK_SET);
fwrite (block, 1, header.block_size, fp);
std::cout << "__NO__ hay lugar para meter la clave" << std::endl;
}
+
+ WriteKeys (root, root_header, node_keys);
+ WriteNodoHeader (root, &root_header);
+ WriteBlock (root, 0);
+
delete [] root;
}
return keys;
}
+void BTree::WriteKeys (uchar *node, BTreeNodeHeader &node_header, std::list<Clave *> &keys)
+{
+ std::list<Clave *>::iterator it = keys.begin ();
+
+ node += sizeof (BTreeNodeHeader);
+
+ while (it != keys.end ()) {
+ Clave *c = (*it);
+ memcpy (node, c->ToArray(), c->Size ());
+ node += c->Size ();
+ it++;
+ }
+
+ /* TODO : incrementar node_header.item_count aca o fuera de este metodo? */
+}