From 01bb8597d243547afdbb673f5fad48d88a00f92b Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Wed, 19 Oct 2005 17:09:58 +0000 Subject: [PATCH] Implemento bajas y altas simultaneas en la GUI. --- viewer/main.cpp | 36 +++++++++++++++++++++++++++++++----- viewer/new_tree_dialog.cpp | 37 +++++++++++++++++++++++++++++++------ viewer/new_tree_dialog.h | 10 ++++++++-- 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/viewer/main.cpp b/viewer/main.cpp index 7a10f11..fc8782b 100644 --- a/viewer/main.cpp +++ b/viewer/main.cpp @@ -102,7 +102,11 @@ void nuevo_arbol () NewTreeDialog d; if (d.run () == Gtk::RESPONSE_OK) { - uint tot = d.getAmount (); + uint altas = d.getAdds (); + uint bajas = d.getDels (); + + double paltas = bajas / (double)altas; + int type = d.getKeyType (); tree = Glib::RefPtr(new ViewBTree (real_canvas->root(), "test.idx", d.getBlockSize (), type)); tree->signal_selected ().connect ( sigc::mem_fun (*real_frame, &ViewProperties::ShowItem) ); @@ -111,21 +115,43 @@ void nuevo_arbol () std::list lst; std::list::iterator it; Random::Init (); - Random::Ints (lst, tot); + Random::Ints (lst, altas); it = lst.begin (); + uint i = 0; while (it != lst.end ()) { ClaveFija c(*it); - tree->AddKey (c); - vdebug->AddKey (c); + double l = Random::Double (0.0f, 1.0f); + std::cout << l << " >= " << paltas << std::endl; + if (l >= paltas) { + tree->AddKey (c); + i++; + vdebug->AddKey (c); + } else { + /* Tengo que borrar una clave entre 0 e "i" de la lista + * porque son las que ya agregue. */ + int aborrar = (int)Random::Double (0, i); + std::list::iterator otro = lst.begin (); + int j = 0; + while (j < aborrar) { + otro++; + j++; + } + ClaveFija c(*otro); + + tree->DelKey (c); + std::string sss = c; + std::cout << "Clave Borrada " << sss << std::endl; + } + it++; } } else { std::list lst; std::list::iterator it; Random::Init (); - Random::Strings (lst, tot); + Random::Strings (lst, altas); it = lst.begin (); while (it != lst.end ()) { diff --git a/viewer/new_tree_dialog.cpp b/viewer/new_tree_dialog.cpp index 7899cc9..edb1f5a 100644 --- a/viewer/new_tree_dialog.cpp +++ b/viewer/new_tree_dialog.cpp @@ -2,31 +2,56 @@ #include "new_tree_dialog.h" -NewTreeDialog::NewTreeDialog(): Gtk::Dialog ("Nuevo Arbol", true, true) +NewTreeDialog::NewTreeDialog(): Gtk::Dialog ("Nuevo Arbol", true, true), + fixed_key ("Clave Fija"), variable_key ("Clave Variable") { + table.attach (fixed_key, 0, 1, 0, 1); + table.attach (variable_key, 1, 2, 0, 1); + label_block.set_label ("Tamaño de Bloque : "); - table.attach (label_block, 0, 1, 0, 1, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 8, 8); - table.attach (entry_block, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK, 8, 8); + table.attach (label_block, 0, 1, 1, 2, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 8, 8); + table.attach (entry_block, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK, 8, 8); label_count.set_label ("Cantidad a insertar : "); - table.attach (label_count, 0, 1, 1, 2, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 8, 8); - table.attach (entry_count, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK, 8, 8); + table.attach (label_count, 0, 1, 2, 3, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 8, 8); + table.attach (entry_count, 1, 2, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK, 8, 8); + + label_dels.set_label ("Cantidad a eliminar : "); + table.attach (label_dels, 0, 1, 3, 4, Gtk::FILL|Gtk::SHRINK, Gtk::SHRINK, 8, 8); + table.attach (entry_dels, 1, 2, 3, 4, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK, 8, 8); get_vbox ()->add (table); add_button (Gtk::StockID ("Cancelar"), Gtk::RESPONSE_CANCEL); add_button (Gtk::StockID ("Crear"), Gtk::RESPONSE_OK); + Gtk::RadioButton::Group group = fixed_key.get_group(); + fixed_key.set_group (group); + variable_key.set_group (group); show_all (); } -uint NewTreeDialog::getAmount () +uint NewTreeDialog::getAdds () { return atoi (entry_count.get_text ().c_str()); } +uint NewTreeDialog::getDels () +{ + std::cout << entry_dels.get_text () << std::endl; + return atoi (entry_dels.get_text ().c_str()); +} + uint NewTreeDialog::getBlockSize() { return atoi (entry_block.get_text ().c_str()); } +int NewTreeDialog::getKeyType () +{ + if (fixed_key.get_active ()) + return BTree::KEY_FIXED; + + return BTree::KEY_VARIABLE; +} + diff --git a/viewer/new_tree_dialog.h b/viewer/new_tree_dialog.h index 0c67de4..1edb27c 100644 --- a/viewer/new_tree_dialog.h +++ b/viewer/new_tree_dialog.h @@ -3,20 +3,26 @@ #define _NUEVO_ARBOL_DLG_ #include +#include "btree.h" class NewTreeDialog : public Gtk::Dialog { public: NewTreeDialog (); - uint getAmount (); + uint getAdds (); + uint getDels (); uint getBlockSize (); - + int getKeyType (); private: Gtk::Table table; Gtk::Label label_count; Gtk::Label label_block; + Gtk::Label label_dels; Gtk::Entry entry_count; + Gtk::Entry entry_dels; Gtk::Entry entry_block; + Gtk::RadioButton fixed_key; + Gtk::RadioButton variable_key; }; #endif -- 2.43.0