From a164e095defb0f86d8dcde22c6054b5e2bc7da7b Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Fri, 23 Sep 2005 20:12:17 +0000 Subject: [PATCH] Fix Insertar con algunos datos que me estaban fantando. --- src/btree.cpp | 21 +++++++++++++++++++-- src/btree_data.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/btree.cpp b/src/btree.cpp index e28bf9e..48f4937 100644 --- a/src/btree.cpp +++ b/src/btree.cpp @@ -132,8 +132,9 @@ Clave* BTree::AddKeyR (const Clave *k, uint node_num, uint &left_child, uint &ri std::cout << "==== Me voy al nodo " << (*ultima)->getChild () << std::endl; k = AddKeyR (k, (*ultima)->getChild (), left_child, right_child); } - if (k) + if (k) { data = new BTreeData (k->Clone (), right_child); + } } @@ -170,19 +171,28 @@ Clave* BTree::AddKeyR (const Clave *k, uint node_num, uint &left_child, uint &ri uint new_node_num; uchar *new_node = NewBlock (new_node_num); ReadNodoHeader (new_node, &new_node_header); + new_node_header.level = node_header.level; node_keys = ReadKeys (node, node_header); new_node_keys = ReadKeys (new_node, new_node_header); /* Agrego la clave en la lista que ya tengo de manera ordenada */ std::list::iterator it = node_keys.begin (); + std::list::iterator previt = node_keys.begin (); + if (node_header.level != 0) { + /* La primera es ChildData */ + it++; + previt = it; + } + while (it != node_keys.end ()) { BTreeData *datait; datait = (*it); if ((*data) < (*datait)) /* Me pase, lo agrego aca! */ break; + previt = it; it++; } if (it != node_keys.end ()) @@ -218,7 +228,14 @@ Clave* BTree::AddKeyR (const Clave *k, uint node_num, uint &left_child, uint &ri used += d->Size (); it++; } - kout = (*it++)->getClave (); // Esta se retorna al "padre" para que se la agregue + kout = (*it)->getClave (); // Esta se retorna al "padre" para que se la agregue + if (node_header.level != 0) { + new_node_keys.push_back ( new BTreeChildData ((*it)->getChild ())); + } + it++; + + std::string s = *kout; + std::cout << "SPLIT Retorna : " << s << std::endl; while (it != node_keys.end ()) { BTreeData *d = (*it); new_node_keys.push_back (d); diff --git a/src/btree_data.h b/src/btree_data.h index 5bbfc27..f7106df 100644 --- a/src/btree_data.h +++ b/src/btree_data.h @@ -20,6 +20,7 @@ class BTreeData { Clave* getClave () { return clave; } uint getChild () { return hijo; } + void setChild (uint c) { hijo = c; } bool operator < (const BTreeData &data) const; virtual operator std::string () const { -- 2.43.0