6 #include <static_bitsequence.h>
7 #include <alphabet_mapper.h>
8 #include <static_sequence.h>
12 void test_static_sequence(uint * symbols, uint n, static_sequence * ss) {
13 cout << "Size: " << ss->size() << endl;
16 max_v = max(max_v,symbols[i]);
17 uint * occ = new uint[max_v+1];
18 for(uint i=0;i<=max_v;i++)
21 for(uint i=0;i<n && !error;i++) {
22 if(i!=0 && i%max(1,(n-1)/100)==0) { cout << "."; cout.flush(); }
23 if(i!=0 && i%max(1,(n-1)/10)==0) cout << endl;
25 uint a = ss->access(i);
26 uint r = ss->rank(symbols[i],i);
27 uint s = ss->select(symbols[i],occ[symbols[i]]);
28 uint rM1 = (i==0)?0:ss->rank(symbols[i],i-1);
29 if(r!=occ[symbols[i]]) {
30 cout << "Error in rank for symbol " << symbols[i] << " at position " << i << endl;
31 cout << "value: " << r << endl;
32 cout << "Expected: " << occ[symbols[i]] << endl;
36 cout << "Error in select for symbol " << symbols[i] << " at position " << occ[symbols[i]] << endl;
37 cout << "value: " << s << endl;
38 cout << "Expected: " << i << endl;
42 cout << "Error in access at position " << i << endl;
43 cout << "value: " << a << endl;
44 cout << "Expected: " << symbols[i] << endl;
47 if(rM1!=occ[symbols[i]]-1) {
48 cout << "Error in rankM1 for symbol " << symbols[i] << " at position " << i-1 << endl;
49 cout << "value: " << rM1 << endl;
50 cout << "Expected: " << occ[symbols[i]]-1 << endl;
55 cout << "Test OK! It works :)" << endl;
59 int main(int argc, char ** argv) {
61 cout << "usage: " << argv[0] << " <file> <samp>" << endl;
64 struct stat text_info;
65 if(stat(argv[1],&text_info)<0) {
66 cout << "could not stat: " << argv[1] << endl;
75 uint n= (uint)text_info.st_size/4;
76 uint * text = new uint[n+1];
77 FILE * fp = fopen(argv[1],"r");
79 cout << "could not open " << argv[1] << endl;
83 cout << "File: " << argv[1] << endl;
84 cout << "Length: " << n << endl;
87 for(uint i=0;i<n;i++) {
89 uint read=fread(&c,sizeof(uint),1,fp);
93 max_symbol = max(max_symbol,text[i]);
99 /*uint *occ = new uint[max_symbol];
100 for(uint i=0;i<max_symbol;i++)
102 for(uint i=0;i<n;i++)
105 alphabet_mapper * am = new alphabet_mapper_none();
106 static_bitsequence_builder * bmb = new static_bitsequence_builder_rrr02(samp);
107 cout << "Building Huffman table..."; cout.flush();
108 wt_coder * wtc = new wt_coder_huff(text,n,am);
109 cout << "done" << endl; cout.flush();
110 cout << "Building static_sequence..."; cout.flush();
111 static_sequence * wt = new static_sequence_wvtree(text,n,wtc,bmb,am);
112 cout << "done" << endl; cout.flush();
115 char * fname = new char[10+string(argv[1]).length()];
116 sprintf(fname,"%s.wt",argv[1]);
117 fp = fopen(fname,"w");
121 fp = fopen(fname,"r");
122 wt = static_sequence::load(fp);
126 test_static_sequence(text,n,wt);
128 cout << "WT Size: " << wt->size() << endl;
129 cout << "ft = " << 1.*wt->size()/(bits(max_symbol-1)*n/8) << endl;