6 #include <static_bitsequence.h>
7 #include <alphabet_mapper.h>
8 #include <static_sequence.h>
12 int main(int argc, char ** argv) {
14 cout << "usage: " << argv[0] << " <file> <samp>" << endl;
17 struct stat text_info;
18 if(stat(argv[1],&text_info)<0) {
19 cout << "could not stat: " << argv[1] << endl;
26 ss << string(argv[2]);
31 uint n= (uint)text_info.st_size;
32 uint * text = new uint[n+1];
33 FILE * fp = fopen(argv[1],"r");
35 cout << "could not open " << argv[1] << endl;
39 cout << "File: " << argv[1] << endl;
40 cout << "Length: " << n << endl;
43 for(uint i=0;i<n;i++) {
45 uint read=fread(&c,sizeof(uchar),1,fp);
49 max_symbol = max(max_symbol,text[i]);
55 /*uint *occ = new uint[max_symbol];
56 for(uint i=0;i<max_symbol;i++)
61 alphabet_mapper * am = new alphabet_mapper_none();
62 static_bitsequence_builder * bmb = new static_bitsequence_builder_rrr02(samp);
63 cout << "Building Huffman table..."; cout.flush();
64 wt_coder * wtc = new wt_coder_huff(text,n,am);
65 cout << "done" << endl; cout.flush();
66 static_sequence * wt = new static_sequence_wvtree(text,n,wtc,bmb,am,true);
69 char * fname = new char[10+string(argv[1]).length()];
70 sprintf(fname,"%s.wt",argv[1]);
71 fp = fopen(fname,"w");
72 cout << "save: " << wt->save(fp) << endl;
75 fp = fopen(fname,"r");
76 wt = static_sequence::load(fp);
80 ((static_sequence_wvtree*)wt)->test_structure(text,n);
82 cout << "WT Size: " << wt->size() << endl;
83 cout << "ft = " << 1.*wt->size()/n << endl;
85 fname = new char[10+string(argv[1]).length()];
86 sprintf(fname,"%s.wt",argv[1]);
87 fp = fopen(fname,"w");
88 cout << "save: " << wt->save(fp) << endl;