-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdepuraindice.cpp
121 lines (106 loc) · 3.52 KB
/
depuraindice.cpp
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// vim: set expandtab tabstop=8 shiftwidth=8 foldmethod=marker:
/** @file depuraindice.cpp
* Depura un índice con un trie-especial
*
* @package Mt77
* @author Vladimir Támara Patiño. [email protected]
* Dominio público. 2009. Sin garantías
* http://creativecommons.org/licenses/publicdomain/
* @version $Id: depuraindice.cpp,v 1.5 2010/03/08 12:02:40 vtamara Exp $
*/
#include <iostream>
#include <iomanip>
#include <list>
#include <vector>
#include <set>
#include <fstream>
#include <istream>
#include <algorithm>
#include <sys/time.h>
#include <sys/stat.h>
#include <getopt.h>
#include "sha256.hpp"
using namespace std;
#include "Pos.hpp"
#include "TrieSDisco.hpp"
void uso()
{
cerr << "depuraindice [-cd] indice" << endl;
cerr << " -c indica que calcularse condensado" << endl;
cerr << " -d imprime representación a la que se calcula condensado" << endl;
exit(1);
}
int examina(istream &is, long p)
{
string cad;
long hermano = 0, hijo = 0;
set<Pos> *cpos = NULL;
string cmd = "";
int sigue = 1;
do {
is.seekg(p);
cout << "Posición: " << p << endl;
cad = leeCad(is);
if (cad.size() > 0) {
hermano = leeNDesp(is);
hijo = leeNDesp(is);
cpos = leePos(is);
cout << "Cadena: " << cad <<
"(" << cad.length() << ")" << endl;
cout << "Hijo menor: " << hijo << endl;
cout << "Hermano mayor: " << hermano << endl;
cout << "Posiciones: " << *cpos << endl;
if (cpos != NULL) {
delete cpos;
cpos = NULL;
}
} else {
cout << "No hay nodo" << endl;
}
cin >> cmd;
if ((cmd == "hijo" || cmd == "i") && hijo > 0) {
sigue = examina(is, hijo);
} else if ((cmd == "hermano" || cmd == "e") && hermano > 0) {
sigue = examina(is, hermano);
} else if ((cmd == "anterior" || cmd == "a")) {
return 1;
}
} while (sigue == 1 && cmd != "salir");
return 0;
}
int main(int argc, char *argv[])
{
bool calcondensado = false;
int ch;
while ((ch = getopt(argc, argv, "cd")) != -1) {
switch (ch) {
case 'c':
calcondensado = true;
break;
default:
uso();
}
}
argc -= optind;
argv += optind;
if (argc != 1) {
uso();
}
//cerr << "argv[0]" << argv[0] << endl;
vector<Doc> docs;
char relacion[MAXLURL];
clog << "Verificando archivo " << argv[0] << endl;
verificaNombre(argv[0], relacion);
if (calcondensado) {
string c = condensado(argv[0], true);
cout << c << endl;
} else {
fstream is(argv[0], ios_base::in);
clog << "Verificando que es indice" << endl;
verificaIndice(is);
clog << "Examinando" << endl;
examina(is, is.tellg());
is.close();
}
return 0;
}