X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/afe75d9ce0838d616897573a46ed7471c3028849..HEAD:/src/btree.cpp diff --git a/src/btree.cpp b/src/btree.cpp index 575ca59..cce0759 100644 --- a/src/btree.cpp +++ b/src/btree.cpp @@ -20,6 +20,8 @@ BTree::BTree (const std::string &name, unsigned int block_size, int tt, int kt, header.tree_type = tt; header.key_type = kt; header.block_data_counter = 0; + strcpy (header.magic, "DILUMA"); + header.magic[6] = '\0'; WriteFileHeader (); /* Creo el primer bloque vacio */ @@ -50,11 +52,25 @@ BTree::BTree (const std::string &name) fclose (fp); } + del = filename + ".blockdel"; + + fp = fopen (del.c_str (), "wb"); + if (fp != NULL) { + uint i; + + while (fread (&i, 1, sizeof (uint), fp)) { + deleted_block_data.push_back (i); + } + + fclose (fp); + } + fp = fopen (name.c_str(), "rb+"); if (!fp) { /* TODO : mandar una exception ? */ return; } + filename = name; ReadFileHeader (); } @@ -73,6 +89,16 @@ BTree::~BTree () it++; } + del = filename + ".del"; + + fp = fopen (del.c_str (), "wb"); + it = deleted_block_data.begin (); + + while (it != deleted_block_data.end ()) { + uint i = *it; + fwrite (&i, 1, sizeof (uint), fp); + it++; + } fclose (fp); }