X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/8d4a4f4d97c0275c9275e1934db6ffabbbbcffa5..555cf8e7b36faa768e40d09665781c468424a91c:/src/btree.cpp?ds=inline diff --git a/src/btree.cpp b/src/btree.cpp index e6dea5b..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 ? */ @@ -1167,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 {