-
Notifications
You must be signed in to change notification settings - Fork 0
/
bool_array.cpp
51 lines (41 loc) · 966 Bytes
/
bool_array.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
#include "bool_array.hpp"
BoolArray ::BoolArray (){
for(int i = 0; i < BOOL_ARRAY_SIZE; i++)
p_bools[i] = 0;
}
bool BoolArray::operator[](int idx) {
return (p_bools[idx / sizeof(bool_unit)] >> (idx % sizeof(bool_unit))) & 1;
}
void BoolArray::setb(int idx) {
p_bools[idx / sizeof(bool_unit)] |= 1 << (idx % sizeof(bool_unit));
}
void BoolArray::clearb(int idx) {
p_bools[idx / sizeof(bool_unit)] &= ~(1 << (idx % sizeof(bool_unit)));
}
void BoolArray::clear_all() {
for(int i = 0; i < BOOL_ARRAY_SIZE; i++)
p_bools[i] = 0;
}
int BoolArray::highest() {
int rt = -1;
for(int i = 0; i < BOOL_ARRAY_SIZE; i++){
for(int j = 0; p_bools[i] >> j; j++){
rt = i*sizeof(bool_unit) +j;
}
}
// for(int i = 0; i < BOOL_ARRAY_SIZE_BITS; i++) {
// if((*this)[i]) {
// rt = i;
// }
// }
return rt;
}
int BoolArray::lowest(){
int rt = -1;
for(int i = BOOL_ARRAY_SIZE_BITS - 1; i >= 0; i--) {
if((*this)[i]) {
rt = i;
}
}
return rt;
}