X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/2ec2ca34d681cc605142fabcd03efce9a73db76e..a7b40a39a402b6f4cbcf1b1a175c0e357704d43f:/src/btree.cpp diff --git a/src/btree.cpp b/src/btree.cpp index 4e00e33..874133c 100644 --- a/src/btree.cpp +++ b/src/btree.cpp @@ -53,7 +53,7 @@ void BTree::WriteBlock (uchar *block, uint num) void BTree::AddKey (const Clave &k) { uint left, right; - Clave *kout = AddKeyR (k.Clone (), 0, left, right); + Clave *kout = AddKeyR (&k, 0, left, right); if (kout) { unsigned short level; @@ -479,7 +479,9 @@ void BTree::DelKeyFromLeaf (Clave *k, uint node_num, uint padre) it = node_keys.begin (); while (it != node_keys.end ()) { if ((*data) == (*(*it))) { + BTreeData *aborrar = (*it); node_keys.erase (it); + delete aborrar; break; } it++; @@ -1140,11 +1142,13 @@ BTreeFindResult *BTree::FindKeyR (const Clave *k, uint node_num) while (it != node_keys.end ()) { if ((*data) == (*(*it))) { /* La encontre!, retorno */ + delete data; delete [] node; DeleteKeys (node_keys); BTreeFindResult *result = new BTreeFindResult (); result->node = node_num; result->header = node_header; + return result; } @@ -1154,19 +1158,27 @@ BTreeFindResult *BTree::FindKeyR (const Clave *k, uint node_num) it++; } + delete data; + /* Si llego aca y estoy en nivel 0 (una hoja) quiere * decir que no lo encontré */ if (node_header.level == 0) { - delete data; + DeleteKeys (node_keys); + delete [] node; return NULL; } /* TODO: Aca faltaria liberar memoria */ + BTreeFindResult *ret; if (it == posterior) - return FindKeyR (k, lchild->getChild ()); - - return FindKeyR (k, (*ultima)->getChild ()); + ret = FindKeyR (k, lchild->getChild ()); + else + ret = FindKeyR (k, (*ultima)->getChild ()); + + DeleteKeys (node_keys); + delete [] node; + return ret; } void BTree::DeleteKeys (std::list &keys)