-TARGETS=btree libbtree.a
+TARGETS=btree btree_var libbtree.a
CXXFLAGS=-Wall -g
#Descomentar si se quiere agregar informacion para profiling
btree: main.o $(BTREE_COMMON)
g++ $(PROF) -o btree main.o $(BTREE_COMMON)
+btree_var: main_var.o $(BTREE_COMMON)
+ g++ $(PROF) -o btree_var main_var.o $(BTREE_COMMON)
+
libbtree.a: $(BTREE_COMMON)
$(AR) cru libbtree.a $(BTREE_COMMON)
--- /dev/null
+
+
+#include "btree.h"
+#include "clave_fija.h"
+#include "random.h"
+#include "keymanager.h"
+
+int main (int argc, char *argv[])
+{
+ int bloque, altas, bajas;
+
+ if (argc != 4) {
+ printf ("Uso : %s <block size> <cantidad de altas> <cantidad de bajas>\n", argv[0]);
+ return 1;
+ }
+
+ bloque = atoi (argv[1]);
+ altas = atoi (argv[2]);
+ bajas = atoi (argv[3]);
+
+ KeyManager<std::string> km;
+ BTree tree ("test.idx", bloque, BTree::KEY_VARIABLE);
+
+ std::list<std::string> lst;
+ std::list<std::string>::iterator it;
+ Random::Init ();
+ Random::Strings (lst, altas);
+
+ double paltas = bajas / (double)(altas + bajas);
+
+ it = lst.begin ();
+ while (it != lst.end ()) {
+ ClaveVariable c(*it);
+
+ double l = Random::Double (0.0f, 1.0f);
+ std::cout << l << " >= " << paltas << std::endl;
+ if (l >= paltas) {
+ std::string sss = c;
+ std::cout << "Clave Agregada " << sss << std::endl;
+ tree.AddKey (c);
+ km.AddValue (*it);
+ it++;
+ } else {
+ /* Tengo que borrar una clave entre 0 e "i" de la lista
+ * porque son las que ya agregue. */
+ ClaveVariable c(km.GetRandom ());
+
+ tree.DelKey (c);
+ std::string sss = c;
+ std::cout << "Clave Borrada " << sss << std::endl;
+ }
+ }
+
+ km.PrintInfo ();
+
+ std::list <std::string> l = km.GetList ();
+ it = l.begin ();
+ int bien = 0;
+ int mal = 0;
+ while (it != l.end ()) {
+ ClaveVariable c(*it);
+ BTreeFindResult *r;
+
+ r = tree.FindKey (c);
+ if (r != NULL) {
+ std::cout << "** Clave " << (*it) << " encontrada.\n";
+ bien++;
+ delete r;
+ } else {
+ std::cout << "** Clave " << (*it) << " NO encontrada.\n";
+ mal++;
+ }
+ it++;
+ }
+
+ std::cout << "\n\n === Resultados ===\n";
+ std::cout << " Hist : " << bien << "\n";
+ std::cout << " Miss : " << mal << "\n";
+ std::cout << " Total : " << (bien+mal) << "\n";
+
+ return 0;
+}
+