uint hi, hd;
Clave *pedida;
- FindB (node_num, padre, hi, hd);
+ FindBrothers (node_num, padre, hi, hd);
if ((pedida = GetKey (hi, 1)) != NULL) {
std::string s = *pedida;
std::cout << "Clave Pedida : " << s << std::endl;
+ pedida = ReplaceKeyInFather (node_num, padre, pedida);
+
node_keys.insert (node_keys.begin (), new BTreeLeafData (pedida));
} else if ((pedida = GetKey (hd, 0)) != NULL) {
std::string s = *pedida;
std::cout << "Clave Pedida : " << s << std::endl;
+ pedida = ReplaceKeyInFather (node_num, padre, pedida);
+
node_keys.push_back (new BTreeLeafData (pedida));
} else {
std::cout << "NADIE ME PUEDE PRESTAR, FUNDIR NODOS\n";
return k;
}
-void BTree::FindB (uint node_num, uint padre, uint &left, uint &right)
+void BTree::FindBrothers (uint node_num, uint padre, uint &left, uint &right)
{
uchar *node;
BTreeNodeHeader node_header;
}
}
+Clave *BTree::ReplaceKeyInFather (uint node_num, uint padre, Clave *k)
+{
+ uchar *node;
+ BTreeNodeHeader node_header;
+ std::list<BTreeData *> node_keys;
+
+ node = ReadBlock (padre);
+ ReadNodoHeader (node, &node_header);
+ node_keys = ReadKeys (node, node_header);
+
+ std::list<BTreeData *>::iterator it = node_keys.begin ();
+ std::list<BTreeData *>::iterator anterior = node_keys.begin ();
+ std::list<BTreeData *>::iterator siguiente;
+
+ BTreeData *lchild = (*it++);
+
+ if (lchild->getChild () == node_num) {
+ Clave *ret = (*it)->getClave ();
+ (*it)->setClave (k);
+
+ WriteKeys (node, node_header, node_keys);
+ WriteNodoHeader (node, &node_header);
+ WriteBlock (node, padre);
+ DeleteKeys (node_keys);
+
+ delete [] node;
+ return ret;
+ }
+
+ while (it != node_keys.end ()) {
+ if ((*it)->getChild () == node_num)
+ break;
+ anterior = it;
+ it++;
+ }
+
+ Clave *ret = (*it)->getClave ();
+ (*it)->setClave (k);
+
+ WriteKeys (node, node_header, node_keys);
+ WriteNodoHeader (node, &node_header);
+ WriteBlock (node, padre);
+ DeleteKeys (node_keys);
+
+ delete [] node;
+ return ret;
+}
+
void BTree::DelKeyFromOther (const Clave &k, BTreeFindResult *r)
{
}