X-Git-Url: https://git.llucax.com/z.facultad/75.52/treemulator.git/blobdiff_plain/8699d7e1ccbda4282f8ba693422f337be31d100b..bf046a4a949bf49aa1209f89f01393fb9806455a:/src/btree.cpp diff --git a/src/btree.cpp b/src/btree.cpp index 4d28e49..e28bf9e 100644 --- a/src/btree.cpp +++ b/src/btree.cpp @@ -103,21 +103,43 @@ Clave* BTree::AddKeyR (const Clave *k, uint node_num, uint &left_child, uint &ri ReadNodoHeader (node, &node_header); if (node_header.level != 0) { + std::cout << "Entrando nodo level = " << node_header.level << std::endl; /* No estoy en una hoja, asi que tengo que buscar * para donde moverme para agregar la clave */ - /* TODO :) */ + std::cout << "Leo Claves" << std::endl; node_keys = ReadKeys (node, node_header); + std::list::iterator it = node_keys.begin (); + std::list::iterator posterior; + std::list::iterator ultima; /* Se supone que la primera es un hijo :) */ - //BTreeData *left_child = (*it); - PrintNode (node_num); - std::cout << "TODO!!" << std::endl; - return NULL; + BTreeData *lchild = (*it++); + posterior = it; + + while (it != node_keys.end ()) { + if ((*data) < (*(*it))) + break; + ultima = it; + it++; + } + + if (it == posterior) { + std::cout << "==== Me voy al nodo " << lchild->getChild () << std::endl; + k = AddKeyR (k, lchild->getChild (), left_child, right_child); + } else { + std::cout << "==== Me voy al nodo " << (*ultima)->getChild () << std::endl; + k = AddKeyR (k, (*ultima)->getChild (), left_child, right_child); + } + if (k) + data = new BTreeData (k->Clone (), right_child); } + /* Nada que hacer */ + if (!k) return NULL; + /* Estoy en una hoja, veo si lo puedo agregar */ if (node_header.free_space > data->Size ()) { @@ -250,6 +272,7 @@ std::list BTree::ReadKeys (uchar *node, BTreeNodeHeader &node_heade { std::list keys; node += sizeof (BTreeNodeHeader); + uint count = node_header.item_count; if (node_header.item_count == 0) return keys; @@ -258,9 +281,10 @@ std::list BTree::ReadKeys (uchar *node, BTreeNodeHeader &node_heade BTreeChildData *d = new BTreeChildData (node); node += d->Size (); keys.push_back (d); + count--; } - for (uint i=0; i