17 BitVector() =
default;
22 inline bool operator[](
size_t index) {
return get(index); }
24 bool get(int64_t index) {
28 int offset = index /
sizeof(uint64_t);
29 int bit = index %
sizeof(uint64_t);
30 if (offset < vector.size()) {
31 uint64_t value = vector[offset];
33 result = (value >> bit) & 1U;
38 void set(int64_t index,
bool value) {
41 max_idx = max(max_idx, index + 1);
42 int offset = index /
sizeof(uint64_t);
43 int bit = index %
sizeof(uint64_t);
44 while (offset >= vector.size()) {
48 if (((vector[offset] >> bit) & 1U) != value) {
52 vector[offset] |= 1UL << bit;
55 vector[offset] &= ~(1UL << bit);
58 if (changeHandler !=
nullptr) {
59 changeHandler(index, value, ref);
67 vector.shrink_to_fit();
70 int size() {
return max_idx; }
73 void setChangeCallback(
void (*hdler)(
int idx,
bool value,
void *ref),
74 void *ref =
nullptr) {
75 changeHandler = hdler;
80 void resize(
int size) {
82 int round_up = size % 64 != 0;
83 vector.resize(size / 64 + round_up);
84 for (
int j=0;j<max_idx;j++){
93 for (
int j = 0; j < max_idx - n; j++) {
99 template <
typename T> T toInt(
int n) {
101 for (
int j = 0; j <
sizeof(T) * 8; j++) {
104 result ^= (-x ^ result) & (1UL << j);
111 Vector<uint64_t> vector;
112 void (*changeHandler)(
int idx,
bool value,
void *ref) =
nullptr;