#include "btree.h"
#include "clave_variable.h"
+#include <list>
+#include <map>
+#include <fstream>
+
+void generar_aleatorio (std::list<std::string> &lst, uint cant);
int main (int argc, char *argv[])
{
return 1;
}
- for (int i=0; i<=atoi(argv[1]); i++) {
- std::stringstream ss;
- std::string s;
- ss << i;
- ss >> s;
- ClaveVariable c(s);
+ std::list<std::string> lst;
+ generar_aleatorio (lst, atoi(argv[1]));
+
+ std::list<std::string>::iterator it = lst.begin ();
+ while (it != lst.end ()) {
+ ClaveVariable c(*it);
- std::cout << "Agregando " << i << std::endl;
+ std::cout << "Agregando " << (*it) << std::endl;
tree.AddKey (c);
+ it++;
}
- for (int i=0; i<=atoi(argv[1]); i++) {
- std::stringstream ss;
- std::string s;
- ss << i;
- ss >> s;
- ClaveVariable c(s);
+ it = lst.begin ();
+ while (it != lst.end ()) {
+ ClaveVariable c(*it);
if (tree.FindKey (c))
- std::cout << i << " encontrada\n";
+ std::cout << (*it) << " encontrada\n";
else
- std::cout << i << " NO encontrada\n";
+ std::cout << (*it) << " NO encontrada\n";
+ it++;
}
return 0;
}
+void get_file (const char *f, std::map<int,std::string> &out, int &cant)
+{
+ std::ifstream reader (f);
+ cant = 0;
+ char l[100];
+
+ while (!reader.eof ()) {
+ reader.getline (l, 100);
+ out[cant] = std::string (l);
+ cant++;
+ }
+}
+
+
+void generar_aleatorio (std::list<std::string> &lst, uint n)
+{
+ std::map<int, std::string> productos;
+ std::map<int, std::string> marcas;
+ int productos_cant, marcas_cant;
+
+ get_file ("productos.txt", productos, productos_cant);
+ get_file ("marcas.txt", marcas, marcas_cant);
+
+ srand (time (NULL));
+ int random1, random2;
+ /* TODO : Evitar repetidos */
+ for (uint i=0; i < n; i++) {
+ random1 = 1 + (int)(productos_cant * (float)rand () / (RAND_MAX + 1.0f));
+ random2 = 1 + (int)(marcas_cant * (float)rand () / (RAND_MAX + 1.0f));
+
+ lst.push_back (productos[random1-1] + " " + marcas[random2-1]);
+ }
+}
+