Create branch library-split
[SXSI/XMLTree.git] / libcds / tests / static_sequence_gmr_test.cpp
1 /* static_sequence_gmr_test.cpp
2  * Copyright (C) 2008, Francisco Claude, all rights reserved.
3  *
4  * static_sequence_gmr_test
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #include <sys/stat.h>
23 #include <iostream>
24 #include <sstream>
25 #include <basics.h>
26 #include <static_bitsequence.h>
27 #include <static_bitsequence_builder.h>
28 #include <alphabet_mapper.h>
29 #include <static_sequence.h>
30 #include <wt_coder.h>
31 #include <static_sequence_builder.h>
32 #include "static_sequence_tester.h"
33
34 int main(int argc, char ** argv) {
35   if(argc!=8) {
36     cout << "Usage: " << argv[0] << " <file> <b|r> <p|w|c> <sampling> <chunk_length> <perm_samp> <t|s>" << endl;
37     return 0;
38   }
39   stringstream ss;
40   ss << argv[4];
41   uint samp;
42   ss >> samp;
43   stringstream ss2;
44   ss2 << argv[5];
45   uint chunk_length;
46   ss2 >> chunk_length;
47         stringstream ss3;
48         ss3 << argv[6];
49         uint perm_samp;
50         ss3 >> perm_samp;
51   
52   uint * text;
53   uint n;
54   load(argv[1],&text,&n);
55     
56   static_bitsequence_builder * bmb;
57   if(string(argv[2])==string("b"))
58     bmb = new static_bitsequence_builder_brw32(samp);
59   else
60     bmb = new static_bitsequence_builder_rrr02(samp);
61   
62   static_sequence_builder * ssb;
63   
64         if(string(argv[3])==string("w")) {
65     alphabet_mapper * am = new alphabet_mapper_cont(text,n,bmb);
66                 ssb = new static_sequence_builder_wvtree_noptrs(bmb,am);
67         }       else if(string(argv[3])==string("p")) {
68     alphabet_mapper * am = new alphabet_mapper_none();
69                 wt_coder * wc = new wt_coder_huff(text,n,am);
70                 ssb = new static_sequence_builder_wvtree(wc,bmb,am);
71   } else {
72     ssb = new static_sequence_builder_gmr_chunk(bmb, new static_permutation_builder_mrrr(perm_samp,bmb));
73   }
74   
75   static_sequence * sseq = new static_sequence_gmr(text,n,chunk_length,bmb,ssb);
76
77         delete bmb;
78         delete ssb;
79
80   sseq = savetest(argv[1], sseq);
81   if(string(argv[7])==string("t"))
82     test_static_sequence(text,n,sseq);
83   else 
84     cout << "Size: " << sseq->size() << endl;
85   cout << "*************************************" << endl;
86   speed_access(sseq,text,n);
87   cout << "*************************************" << endl;
88   speed_rank(sseq,text,n);
89   cout << "*************************************" << endl;
90   speed_select(sseq,text,n);
91   
92   delete sseq;
93   delete [] text;
94 }
95