Created
June 24, 2014 03:40
-
-
Save ranisalt/481a384fe146a609eed2 to your computer and use it in GitHub Desktop.
Arquivo que não foi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <sys/time.h> | |
#include "avl_tree.h" | |
#include "red_black_tree.h" | |
class logradouro { | |
public: | |
logradouro(std::string nome, int cep) { | |
_nome = nome; | |
_cep = cep; | |
} | |
bool operator<(const logradouro& rhs) const { | |
return _cep < rhs._cep; | |
} | |
bool operator>(const logradouro& rhs) const { | |
return rhs < *this; | |
} | |
private: | |
std::string _nome; | |
int _cep; | |
}; | |
long diff(timeval inicio, timeval fim) { | |
long diferenca, segundos, usegundos; | |
segundos = fim.tv_sec - inicio.tv_sec; | |
usegundos = fim.tv_usec - inicio.tv_usec; | |
diferenca = segundos * 1000000 + usegundos; | |
return diferenca; | |
} | |
timeval tempo() { | |
timeval tempo; | |
gettimeofday(&tempo, NULL); | |
return tempo; | |
} | |
int main(int argc, char** argv) { | |
using std::cout; | |
using std::endl; | |
using std::ifstream; | |
using std::ofstream; | |
using std::string; | |
avl_tree<logradouro> avlt; | |
red_black_tree<logradouro> rbt; | |
ifstream input; | |
ofstream avlo, rbo, conf; | |
input.open(argv[1]); | |
avlo.open(argv[2]); | |
rbo.open(argv[3]); | |
string line; | |
string nome; | |
int cep; | |
int cont = 0; | |
timeval inicio, fim; | |
while (!input.eof()) { | |
std::getline(input, line); | |
nome = line.substr(0, line.find_first_of("|")); | |
cep = atoi(line.substr(line.find_first_of("|") + 1, line.size()).c_str()); | |
logradouro log(nome, cep); | |
inicio = tempo(); | |
avlt.insert(log); | |
fim = tempo(); | |
avlo << ++cont << ' ' << diff(inicio, fim) << endl; | |
inicio = tempo(); | |
rbt.insert(log); | |
fim = tempo(); | |
rbo << ++cont << ' ' << diff(inicio, fim) << endl; | |
} | |
conf.open(".conf"); | |
conf << "set title \"Diferença entre tempos de inserção - " << argv[1] << "\"" << endl; | |
conf << "set xlabel \"Quantidade de nós\"" << endl; | |
conf << "set ylabel \"microssegundos\"" << endl; | |
conf << "plot \"" << argv[2] << "\" title \"avl\" with lines,\\" << endl; | |
conf << "\"" << argv[3] << "\" title \"red-black\" with lines" << endl; | |
std::system("gnuplot -persist .conf && rm .conf"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment