-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflex_bitset.cpp
63 lines (55 loc) · 1.37 KB
/
flex_bitset.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
// iran
#include <bits/stdc++.h>
using namespace std;
class Bitset {
using dui = deque<uint64_t>;
dui data;
void trim() {
while (data.size() && data.front() == 0) {
data.pop_front();
}
}
public:
Bitset(string s) {
reverse(s.begin(), s.end());
while (s.size() % 64) {
s += '0';
}
reverse(s.begin(), s.end());
for (int i = 0; i < s.size() / 64; i++) {
data.push_back(stoull(s.substr(64 * i, 64 * (i + 1)), 0, 2));
}
trim();
}
void operator<<(const int n) {
int size = data.size();
int jump = (n + 63) / 64;
for (int i = 0; i < jump; i++) {
data.push_front(0);
}
int offset = n % 64;
for (int i = 0; i < size; i++) {
data[i] |= data[i + jump] >> (64 - offset);
data[i + 1] |= data[i + jump] << offset;
if (i == size - 1) {
data[i + 1] &= (0ull - 1) << offset;
for (int j = i + 2; j < data.size(); j++) {
data[j] = 0;
}
}
}
trim();
}
void print_data() {
for (uint64_t d: data) {
cout << d << ' ';
}
cout << endl;
}
};
int main() {
Bitset hoge("000110");
hoge.print_data();
hoge << 2;
hoge.print_data();
}