-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRangedBitset.hpp
85 lines (58 loc) · 2.1 KB
/
RangedBitset.hpp
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
75
76
77
78
79
80
81
82
83
#pragma once
#include <cstring>
#include <cstdint>
#include <cassert>
namespace andviane {
template<unsigned int SIZE_BITS>
class RangedBitset {
public:
RangedBitset();
// Set the value of the single bit.
void set(int bit, bool value);
// Check the value of the single bit
bool check(int bit);
// Set all bits to the given value
void set(bool value);
// Set all bits to 0.
void clear();
// Set range of bits to the given value
void set(int from_inclusive, int end_exclusive, bool value);
// Check if all bits in the range have the same value.
bool check_all(int from_inclusive, int end_exclusive, bool value) const;
// Bitwise and operation between this and other set.
void bitwise_and(const RangedBitset &other);
// Biwise or operation between this and other set.
void bitwise_or(const RangedBitset &other);
// Clear the bits in thist set that are on in the other set.
void bitwise_clear(const RangedBitset &other);
// Invert the current set (bitwise not).
void invert();
std::string DebugString() const;
// Access to raw data may be needed for serialization.
void *data();
// May be needed for serialization
size_t size_bytes() const;
// Overloading some operators for more convenience
// Checks the needed bit.
bool operator[](int bit) const;
// const version (required by assertions in tests)
// Returns true for a non empty bitset. This is
// optimized implementation that does not scan all set every time.
operator bool() const;
// Returns true for a non empty bitset. This is
// optimized implementation that does not scan all set every time.
operator bool();
// Non operator version
bool empty();
private:
static const unsigned int SIZE_WORDS = SIZE_BITS / 64;
uint64_t bits_[SIZE_WORDS];
// Optimization flag that states the set is surely empty.
bool sure_empty_;
// Which word does the bit belong
int word(int bit) const;
// Which bit does the bit belong
int bit(int bit) const;
};
#include "internal/RangedBitset.tpp"
}