4470f2478365f0209f55fd3609dd4f1074d5c9c5
[SXSI/XMLTree.git] / libcds / tests / static_sequence_wvtree_test.cpp
1 /* static_sequence_wvtree_test.cpp
2  * Copyright (C) 2008, Francisco Claude, all rights reserved.
3  *
4  * static_sequence_wvtree_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 <static_sequence_builder.h>
31 #include "static_sequence_tester.h"
32
33 int main(int argc, char ** argv) {
34   if(argc!=6) {
35     cout << "Usage: " << argv[0] << " <file> <b|r> <h|p> <sampling> <t|s>" << endl;
36     return 0;
37   }
38   stringstream ss;
39   ss << argv[4];
40   uint samp;
41   ss >> samp;
42   
43   uint * text;
44   uint n;
45   load(argv[1],&text,&n);
46   
47   alphabet_mapper * am = new alphabet_mapper_none();
48   
49   static_bitsequence_builder * bmb;
50   if(string(argv[2])==string("b"))
51     bmb = new static_bitsequence_builder_brw32(samp);
52   else
53     bmb = new static_bitsequence_builder_rrr02(samp);
54   
55   wt_coder * wc;
56   if(string(argv[3])==string("p"))
57     wc = new wt_coder_binary(text,n,am);
58   else
59     wc = new wt_coder_huff(text,n,am);
60     
61   static_sequence_builder * ssb = new static_sequence_builder_wvtree(wc,bmb,am);
62   static_sequence * sseq = ssb->build(text,n);
63   delete bmb;
64   delete ssb;
65   
66   sseq = savetest(argv[1], sseq);
67   if(string(argv[5])==string("t"))
68     test_static_sequence(text,n,sseq);
69   else 
70     cout << "Size: " << sseq->size() << endl;
71   cout << "*************************************" << endl;
72   speed_access(sseq,text,n);
73   cout << "*************************************" << endl;
74   speed_rank(sseq,text,n);
75   cout << "*************************************" << endl;
76   speed_select(sseq,text,n);
77   
78   delete sseq;
79   delete [] text;
80 }
81