Create branch library-split
[SXSI/XMLTree.git] / libcds / tests / static_bitsequence_test.cpp
1 /* static_bitsequence_test.cpp
2  * Copyright (C) 2008, Francisco Claude, all rights reserved.
3  *
4  * static_bitsequence_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 <iostream>
23 #include <sstream>
24 #include <basics.h>
25 #include <static_bitsequence.h>
26 #include "static_bitsequence_tester.h"
27
28 using namespace std;
29
30 int main(int argc, char ** argv) {
31         if(argc!=5) {
32                 cout << "usage: " << argv[0] << " <bitmap_file> <b|r|s> <sample_rate> <t|s>" << endl;
33                 return 0;
34         }
35         FILE * fp = fopen(argv[1],"r");
36         if(fp==NULL) {
37                 cout << "Error opening " << argv[1] << endl;
38                 return -1;
39         }
40         uint *bitseq, len;//, ones;
41         uint l=fread(&len, sizeof(uint), 1, fp);
42         //l += fread(&ones,sizeof(uint),1,fp);
43         bitseq = new uint[uint_len(len,1)];
44         l+=fread(bitseq, sizeof(uint), uint_len(len,1), fp);
45         fclose(fp);
46
47   uint sample_rate;
48   stringstream ss(argv[3]);
49   ss >> sample_rate;
50   
51         static_bitsequence * bs;
52   
53   if(string(argv[2])==string("r")) bs = new static_bitsequence_rrr02(bitseq,len,sample_rate);
54   if(string(argv[2])==string("s")) bs = new static_bitsequence_sdarray(bitseq,len);
55   else bs = new static_bitsequence_brw32(bitseq,len,sample_rate);
56         
57   cout << "Size: " << bs->size() << endl;
58   cout << "bpb = " << bs->size()*8./len << endl;
59   
60         /*for(uint kk=0;kk<30;kk++)
61                 cout << bs->access(kk);
62         cout << endl;*/
63
64         /*for(uint kk=0;kk<20;kk++) {
65                 bs->select_next1(kk);
66         }*/
67
68         if(string(argv[4])==string("t"))
69           test_bitsequence(bitseq,len,bs);
70   cout << "******************************************" << endl;
71   speed_access(bs, bitseq, len);
72   cout << "******************************************" << endl;
73   speed_rank0(bs, bitseq, len);
74   cout << "******************************************" << endl;
75   speed_rank1(bs, bitseq, len);
76   cout << "******************************************" << endl;
77   speed_select0(bs, bitseq, len);
78   cout << "******************************************" << endl;
79   speed_select1(bs, bitseq, len);
80   cout << "******************************************" << endl;
81   speed_selectnext1(bs, bitseq, len);
82 }