From d9f6b6c969656b47f1e6a051cfc65959bd5c069f Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Mon, 3 Oct 2005 04:10:58 +0000 Subject: [PATCH] Agrego test de borrado de una hoja. --- src/Makefile | 5 +++- src/btree.h | 1 + src/main_con_delete.cpp | 57 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main_con_delete.cpp diff --git a/src/Makefile b/src/Makefile index 2bcafd6..a496d72 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -TARGETS=btree btree_variable libbtree.a +TARGETS=btree btree_variable btree_delete libbtree.a CXXFLAGS=-Wall -g BTREE_COMMON=btree.o clave_fija.o btree_data.o clave_variable.o @@ -8,6 +8,9 @@ all: $(TARGETS) btree: main.o $(BTREE_COMMON) g++ -o btree main.o $(BTREE_COMMON) +btree_delete: main_con_delete.o $(BTREE_COMMON) + g++ -o btree_delete main_con_delete.o $(BTREE_COMMON) + btree_variable: main_variable.o $(BTREE_COMMON) g++ -o btree_variable main_variable.o $(BTREE_COMMON) diff --git a/src/btree.h b/src/btree.h index e67c7cf..df427ed 100644 --- a/src/btree.h +++ b/src/btree.h @@ -143,6 +143,7 @@ class BTree { /* DEBUG */ + public: void PrintNode (uint num); }; diff --git a/src/main_con_delete.cpp b/src/main_con_delete.cpp new file mode 100644 index 0000000..a6148f2 --- /dev/null +++ b/src/main_con_delete.cpp @@ -0,0 +1,57 @@ + + +#include "btree.h" +#include "clave_fija.h" +#include "random.h" + +int main (int argc, char *argv[]) +{ + std::list lst; + + BTree tree ("test.idx", 512); + + + Random::Init (); + + Random::Ints (lst, 10); + + std::list::iterator it = lst.begin (); + while (it != lst.end ()) { + ClaveFija c(*it); + + std::cout << "Agregando " << (*it) << std::endl; + tree.AddKey (c); + it++; + } + + it = lst.begin (); + BTreeFindResult *r; + while (it != lst.end ()) { + ClaveFija c(*it); + + r = tree.FindKey (c); + if (r) { + std::cout << (*it) << " encontrada\n"; + delete r; + } else + std::cout << (*it) << " NO encontrada\n"; + it++; + } + + it = lst.begin (); + while (it != lst.end ()) { + ClaveFija c(*it); + + std::cout << "========= Borro : " << (*it)<< "============\n"; + tree.PrintNode (0); + tree.DelKey (c); + std::cout << std::endl; + tree.PrintNode (0); + it++; + std::cout << "=============================\n"; + } + + + return 0; +} + -- 2.43.0