-
Notifications
You must be signed in to change notification settings - Fork 1
/
bitVecTest.cpp
74 lines (63 loc) · 1.51 KB
/
bitVecTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <vector>
#include <cstdlib>
#include "bitVec.hpp"
#include "fujimapCommon.hpp"
using namespace std;
int main(int argc, char* argv[]){
const uint64_t n = 1000000;
vector<uint32_t> v;
vector<uint32_t> sv;
BitVec bv(n);
for (uint64_t i = 0; i < n; ++i){
int b = rand() % 2;
v.push_back(b);
if (b){
sv.push_back(i);
bv.setBit(i);
}
}
// check
cerr << "getBit test" << endl;
for (uint64_t i = 0; i < n; ++i){
if (v[i] != bv.getBit(i)){
cerr << "error i:" << i << " v[i]:" << v[i] << " bv.getBit(i):" << bv.getBit(i) << endl;
return -1;
}
}
cerr << "done" << endl;
cerr << "getBits test" << endl;
for (uint64_t i = 0; i < n; ++i){
uint32_t code = 0;
for (uint32_t j = 0; j < 10; ++j){
code |= (bv.getBit(i + j)) << j;
}
uint32_t code2 = bv.getBits(i, 10);
if (code != code2) {
cerr << "error i:" << i << " code:" << code <<" getBits:" << code2 << endl;
for (int j = 0; j < 10; ++j){
cerr << ((code >> j) & 1U) << " " << ((code2 >> j) & 1U) << endl;
}
return -1;
}
}
BitVec bv2(n);
for (uint64_t i = 0; i < n; ++i){
bv2.setBit(i);
}
size_t offset = 0;
for (int i = 0; i < 63; ++i){
if ((i % 2) == 0) {
bv2.setBits(offset, i+1, 0);
}
offset += (i+1);
}
offset = 0;
for (int i = 0; i < 63; ++i){
uint64_t bits = bv2.getBits(offset, i+1);
fujimap_tool::printBit(bits, i+1);
offset += (i+1);
}
cerr << "done" << endl;
return 0;
}