X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/6a4238b2894a1cf20a5b8ccb0575f018ae25a5b3..a4c2bc5e5d6b2a6cfdae3ae0159535deaacd28f4:/src/btree.cpp diff --git a/src/btree.cpp b/src/btree.cpp index adb0ae7..a063bef 100644 --- a/src/btree.cpp +++ b/src/btree.cpp @@ -45,14 +45,15 @@ void BTree::WriteFileHeader () void BTree::WriteBlock (uchar *block, uint num) { - fseek (fp, num*header.block_size + sizeof (BTreeFileHeader), SEEK_SET); + num++; + fseek (fp, num*header.block_size, SEEK_SET); fwrite (block, 1, header.block_size, fp); } void BTree::AddKey (const Clave &k) { uint left, right; - Clave *kout = AddKeyR (&k, 0, left, right); + Clave *kout = AddKeyR (k.Clone (), 0, left, right); if (kout) { unsigned short level; @@ -91,8 +92,6 @@ void BTree::AddKey (const Clave &k) delete [] node; DeleteKeys (node_keys); PrintNode (0); - - delete kout; } } @@ -404,9 +403,14 @@ void BTree::WriteNodoHeader (uchar *node, BTreeNodeHeader *header) uchar *BTree::ReadBlock (uint num) { + /* Como el bloque 0 se usa para el header, el Nodo "num" + * está en el bloque "num+1" + */ + num++; + uchar *out = new uchar[header.block_size]; - fseek (fp, num*header.block_size + sizeof (BTreeFileHeader), SEEK_SET); + fseek (fp, num*header.block_size, SEEK_SET); fread (out, 1, header.block_size, fp); return out; @@ -503,7 +507,7 @@ uchar *BTree::NewBlock (uint &num) fseek (fp, 0, SEEK_END); filelen = ftell (fp); - num = (filelen - sizeof (BTreeFileHeader))/header.block_size; + num = filelen/header.block_size - 1; node = new uchar[header.block_size]; ReadNodoHeader (node, &nh);