X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/358553d9f9e9f4414e54d210807fb27832117884..555cf8e7b36faa768e40d09665781c468424a91c:/src/btree.cpp?ds=sidebyside diff --git a/src/btree.cpp b/src/btree.cpp index 0ad4961..e78a91e 100644 --- a/src/btree.cpp +++ b/src/btree.cpp @@ -35,6 +35,20 @@ BTree::BTree (const std::string &name, unsigned int block_size, int tt, int kt, 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 ? */ @@ -46,6 +60,19 @@ BTree::BTree (const std::string &name) BTree::~BTree () { fclose (fp); + + std::string del = filename + ".del"; + + fp = fopen (del.c_str (), "wb"); + std::list::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 () @@ -1154,9 +1181,9 @@ uchar *BTree::NewBlock (uint &num) BTreeNodeHeader nh; std::list::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 {