X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/2c1d3ea3cf9a25e8f957587d4a1581fc292c831b..7fbdb57d39dea2e7545271be5d706c2df5b5b095:/src/btree.cpp diff --git a/src/btree.cpp b/src/btree.cpp index cf01b2c..5df88a2 100644 --- a/src/btree.cpp +++ b/src/btree.cpp @@ -55,7 +55,7 @@ void BTree::AddKey (const Clave &k) Clave* BTree::AddKeyR (const Clave *k, uint node_num) { - Clave *kout; + Clave *kout = NULL; std::list node_keys; /* Leo el nodo raiz para empezar a agregar */ @@ -67,18 +67,23 @@ Clave* BTree::AddKeyR (const Clave *k, uint node_num) if (node_header.free_space >= k->Size ()) { /* TODO : Insertar ordenado */ - //node_keys.push_back (BTreek->Clone ()); + /* Siempre se agrega en una hoja */ + node_keys.push_back (BTreeLeafData (k->Clone ())); + + WriteKeys (node, node_header, node_keys); + WriteNodoHeader (node, &node_header); + WriteBlock (node, node_num); + delete [] node; } else { /* Split */ + /* Lo que debe pasar : + * 1) Separar N/2 claves en "nodo" + * 2) Separar N/2-1 claves en un nuevo nodo + * 3) kout = clave del medio y mandarla al padre + */ + std::cout << "SPLIT" << std::endl; } - - WriteKeys (node, node_header, node_keys); - WriteNodoHeader (node, &node_header); - WriteBlock (node, node_num); - - delete [] node; - return kout; } @@ -129,10 +134,15 @@ void BTree::WriteKeys (uchar *node, BTreeNodeHeader &node_header, std::list