using namespace std;
+void test_static_sequence(uint * symbols, uint n, static_sequence * ss) {
+ cout << "Size: " << ss->size() << endl;
+ uint max_v=0;
+ for(uint i=0;i<n;i++)
+ max_v = max(max_v,symbols[i]);
+ uint * occ = new uint[max_v+1];
+ for(uint i=0;i<=max_v;i++)
+ occ[i] = 0;
+ bool error = false;
+ for(uint i=0;i<n && !error;i++) {
+ if(i!=0 && i%max(1,(n-1)/100)==0) { cout << "."; cout.flush(); }
+ if(i!=0 && i%max(1,(n-1)/10)==0) cout << endl;
+ occ[symbols[i]]++;
+ uint a = ss->access(i);
+ uint r = ss->rank(symbols[i],i);
+ uint s = ss->select(symbols[i],occ[symbols[i]]);
+ uint rM1 = (i==0)?0:ss->rank(symbols[i],i-1);
+ if(r!=occ[symbols[i]]) {
+ cout << "Error in rank for symbol " << symbols[i] << " at position " << i << endl;
+ cout << "value: " << r << endl;
+ cout << "Expected: " << occ[symbols[i]] << endl;
+ error = true;
+ }
+ if(s!=i) {
+ cout << "Error in select for symbol " << symbols[i] << " at position " << occ[symbols[i]] << endl;
+ cout << "value: " << s << endl;
+ cout << "Expected: " << i << endl;
+ error = true;
+ }
+ if(a!=symbols[i]) {
+ cout << "Error in access at position " << i << endl;
+ cout << "value: " << a << endl;
+ cout << "Expected: " << symbols[i] << endl;
+ error = true;
+ }
+ if(rM1!=occ[symbols[i]]-1) {
+ cout << "Error in rankM1 for symbol " << symbols[i] << " at position " << i-1 << endl;
+ cout << "value: " << rM1 << endl;
+ cout << "Expected: " << occ[symbols[i]]-1 << endl;
+ error = true;
+ }
+ }
+ if(!error)
+ cout << "Test OK! It works :)" << endl;
+ delete [] occ;
+}
+
int main(int argc, char ** argv) {
if(argc!=3) {
cout << "usage: " << argv[0] << " <file> <samp>" << endl;
cout << "Building Huffman table..."; cout.flush();
wt_coder * wtc = new wt_coder_huff(text,n,am);
cout << "done" << endl; cout.flush();
- static_sequence * wt = new static_sequence_wvtree(text,n,wtc,bmb,am,true);
+ cout << "Building static_sequence..."; cout.flush();
+ static_sequence * wt = new static_sequence_wvtree(text,n,wtc,bmb,am);
+ cout << "done" << endl; cout.flush();
delete bmb;
char * fname = new char[10+string(argv[1]).length()];
fclose(fp);
delete [] fname;
- ((static_sequence_wvtree*)wt)->test_structure(text,n);
+ test_static_sequence(text,n,wt);
cout << "WT Size: " << wt->size() << endl;
cout << "ft = " << 1.*wt->size()/n << endl;