]> git.llucax.com Git - z.facultad/75.52/treemulator.git/blobdiff - src/btree.cpp
Agrego métodos y atributos al diagrama de clases.
[z.facultad/75.52/treemulator.git] / src / btree.cpp
index ae98139ae0de2bc285a634db577e6cd7db2fb12e..a063befcafc4d49cfb9b2c5f8fc59e8711a122d5 100644 (file)
@@ -45,7 +45,8 @@ 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);
 }
 
@@ -402,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;
@@ -501,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);