New (faster) representation for tags added; faster construction of parentheses
[SXSI/XMLTree.git] / libcds / tests / make_bitmap.cpp
1 /* make_bitmap.cpp
2  * Copyright (C) 2008, Francisco Claude, all rights reserved.
3  *
4  * make_bitmap
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 <cstring>
24 #include <cstdlib>
25 #include <basics.h>
26 #include <cmath>
27
28 using namespace std;
29
30 int main(int argc, char ** argv) {
31         if(argc!=4) {
32                 cout << "usage: " << argv[0] << " <bitmap> <length> <ones>" << endl;
33                 return 0;
34         }
35         char * fname = argv[1];
36         uint len = atoi(argv[2]);
37         uint ones = atoi(argv[3]);
38         uint * bm = new uint[uint_len(len,1)];
39         for(uint i=0;i<uint_len(len,1);i++)
40                 bm[i] = 0;
41         for(uint i=0;i<ones;i++) {
42                 while(true) {
43                         uint p = rand()%len;
44                         if(!bitget(bm,p)) {
45                                 bitset(bm,p);
46                                 break;
47                         }
48                 }
49         }
50         FILE * fp = fopen(fname,"w");
51         uint l = fwrite(&len,sizeof(uint),1,fp);
52         l += fwrite(bm,sizeof(uint),uint_len(len,1),fp);
53         fclose(fp);
54         delete [] bm;
55         return 0;
56 }
57