-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitVector256.h
44 lines (33 loc) · 919 Bytes
/
BitVector256.h
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
#ifndef BitVector256_h
#define BitVector256_h
#include <stdint.h> // uint16_t
#include <cstring> // memset
class BitVector256 {
public:
static const unsigned VECTOR_SIZE = 16;
BitVector256() {
clearAll();
}
inline void set(unsigned x, unsigned y) {
if(x < VECTOR_SIZE && y < VECTOR_SIZE)
vector[x] |= 1<<y;
}
inline void clear(unsigned x, unsigned y) {
if(x < VECTOR_SIZE && y < VECTOR_SIZE)
vector[x] &= ~(1<<y);
}
inline bool get(unsigned x, unsigned y) const {
if(x < VECTOR_SIZE && y < VECTOR_SIZE)
return (vector[x] & 1<<y) != 0;
return 0;
}
inline void clearAll() {
memset(vector, 0, sizeof(vector));
}
inline void setAll() {
memset(vector, ~0, sizeof(vector));
}
protected:
uint16_t vector[(VECTOR_SIZE * VECTOR_SIZE) / (8*sizeof(uint16_t))];
};
#endif