delete [] node;
}
+BTree::BTree (const std::string &name)
+{
+ /* Leo los bloques recuperables */
+ std::string del = filename + ".del";
+
+ fp = fopen (del.c_str (), "wb");
+ if (fp != NULL) {
+ uint i;
+
+ while (fread (&i, 1, sizeof (uint), fp)) {
+ deleted_nodes.push_back (i);
+ }
+
+ fclose (fp);
+ }
+
+ fp = fopen (name.c_str(), "rb+");
+ if (!fp) {
+ /* TODO : mandar una exception ? */
+ return;
+ }
+ ReadFileHeader ();
+}
+
BTree::~BTree ()
{
fclose (fp);
+
+ std::string del = filename + ".del";
+
+ fp = fopen (del.c_str (), "wb");
+ std::list<uint>::iterator it = deleted_nodes.begin ();
+
+ while (it != deleted_nodes.end ()) {
+ uint i = *it;
+ fwrite (&i, 1, sizeof (uint), fp);
+ it++;
+ }
+
+ fclose (fp);
+}
+
+void BTree::ReadFileHeader ()
+{
+ fseek (fp, 0L, SEEK_SET);
+ fread (&header, 1, sizeof (BTreeFileHeader), fp);
}
void BTree::WriteFileHeader ()
BTreeNodeHeader nh;
std::list<uint>::iterator it;
- it = deleted_nodes.begin ();
- if (it != deleted_nodes.end ()) {
+ if (deleted_nodes.size ()) {
+ it = deleted_nodes.begin ();
num = *it;
deleted_nodes.erase (it);
} else {