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;
delete [] node;
DeleteKeys (node_keys);
PrintNode (0);
-
- delete kout;
}
}
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;
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);