-
Notifications
You must be signed in to change notification settings - Fork 0
/
questao5.c
95 lines (76 loc) · 2.36 KB
/
questao5.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "common/common.h"
#include <time.h>
#include "structs/header/hashTableDLL.h"
#include "structs/header/hashTableRBT.h"
int main(int argc, char *argv[]){
if(argc == 1){
printLn("Estrutura inválida!");
printLn("Estruturas: dll ou rbt.");
return 1;
}
if(argc == 2){
printLn("Arquivo inálido!");
printLn("Informe o caminho de um arquivo válido.");
return 1;
}
if(argc == 3){
printLn("Tamanho de buffer inválido");
printLn("Informe um tamanho de buffer válido.");
return 1;
}
int size = atoi(argv[3]);
if(size <= 0){
printLn("Tamanho de buffer inválido!");
printLn("Informe um tamanho de buffer válido.");
return 1;
}
String structName = newString(argv[1]);
String fileName = newString(argv[2]);
int *data = (int *) malloc(sizeof(int) * size);
size = readOutputFile(fileName, data, size);
long int t = 0;
int rCode = 0;
HashTable ht = NULL;
int htSize = 10;
char outputFile[255];
char datetime[100];
time_t now = time(0);
strftime (datetime, 100, "%Y-%m-%dT%H:%M:%S", localtime (&now));
sprintf(outputFile, "output/out-%s-%s_%s.txt", getCStr(structName), argv[3], datetime);
if(cStrIsEqual(structName, "dll")){
ht = newHashTableIntDll(htSize);
t = getMicroTime();
for(int i = 0; i < size; i++) insertHashTableIntDll(ht, data[i]);
t = getMicroTime() - t;
FILE * rbFile;
rbFile = fopen (outputFile , "w+");
if (rbFile != NULL){
fPrintHashTableIntDll(ht, rbFile);
fclose(rbFile);
}
deleteHashTableIntDll(ht);
}
else if(cStrIsEqual(structName, "rbt")){
ht = newHashTableIntRbt(htSize);
t = getMicroTime();
for(int i = 0; i < size; i++) insertHashTableIntRbt(ht, data[i]);
t = getMicroTime() - t;
FILE * rbFile;
rbFile = fopen (outputFile , "w+");
if (rbFile != NULL){
fPrintHashTableIntRbt(ht, rbFile);
fclose(rbFile);
}
deleteHashTableIntRbt(ht);
}
else{
printLn("Estrutura inválida!");
printLn("Estruturas: dll ou rbt.");
rCode = 1;
}
if(rCode == 0) printf("%ld", t);
deleteString(structName);
deleteString(fileName);
free(data);
return rCode;
}