forked from rdfhdt/hdt-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestTextIndex.cpp
63 lines (50 loc) · 1.33 KB
/
testTextIndex.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
#include <cstdlib>
#include <libcdsTrees.h>
#include <TextIndex.h>
using namespace std;
using namespace cds_utils;
using namespace cds_static;
TextIndex * saveLoad(TextIndex * bs) {
ofstream ofs("textindex.tmp");
bs->save(ofs);
ofs.close();
ifstream ifs("textindex.tmp");
TextIndex * ret = TextIndex::load(ifs);
ifs.close();
return ret;
}
bool testTextIndex(TextIndex *s1, TextIndex *s2){
for(size_t i=0; i<s2->index_length(); i++){
if(s1->getSA(i)!=s2->getSA(i))
return false;
if(s1->getISA(i)!=s2->getISA(i))
return false;
if(s1->getPsi(i)!=s2->getPsi(i))
return false;
}
return true;
}
int main(int argc, char ** argv) {
if(argc!=2) {
cout << "Checks if the TextIndex of the file <arch> is save/load correctly" << endl << endl;
cout << "usage: " << argv[0] << " <arch>" << endl;
return 0;
}
char *text=NULL;
size_t length;
TextIndex *ticsa, *load_ticsa;
if(loadText(argv[1], &text, &length))
return 1;
cout << "length: " << length << endl;
ticsa = new TextIndexCSA((uchar *)text, (ulong)length, NULL);
load_ticsa = saveLoad(ticsa);
if(!testTextIndex(ticsa, load_ticsa)) {
cerr << "ERROR TESTING TextIndexCSA" << endl;
return -1;
}
cout << "CSA OK\n" << endl;
delete (TextIndexCSA *)ticsa;
delete (TextIndexCSA *)load_ticsa;
if(text!=NULL)
delete text;
}