|
Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
21 #ifndef ELM_UTIL_BIT_VECTOR_H
22 #define ELM_UTIL_BIT_VECTOR_H
24 #include <elm/assert.h>
26 #include <elm/PreIterator.h>
39 inline int size(
void)
const {
return _size; }
41 inline bool bit(
int i)
const {
42 ASSERTP(i < _size,
"index out of bounds");
43 return (bits[windex(i)] & (1 << bindex(i))) != 0;
48 for(
int i = 0; i < wcount(); i++)
49 if(bits[i])
return false;
60 inline void set(
int index)
const
61 { ASSERTP(index < _size,
"index out of bounds"); bits[windex(index)] |= word_t(1) << bindex(index); }
63 { ASSERTP(index < _size,
"index out of bounds");
if(
value)
set(index);
else clear(index); }
64 inline void clear(
int index)
const
65 { ASSERTP(index < _size,
"index out of bounds"); bits[windex(index)] &= ~(word_t(1) << bindex(index)); }
76 inline void shiftLeft(
int n = 1) { doShiftLeft(n, bits); }
77 inline void shiftRight(
int n = 1) { doShiftRight(n, bits); }
78 inline void rotateLeft(
int n = 1) { doRotateLeft(n, bits); }
79 inline void rotateRight(
int n = 1) { doRotateRight(n, bits); }
88 inline BitVector makeShiftRight(
int n = 1)
const {
BitVector r(
size()); doShiftRight(n, r.bits);
return r; }
89 inline BitVector makeRotateLeft(
int n = 1)
const {
BitVector r(
size()); doRotateLeft(n, r.bits);
return r; }
90 inline BitVector makeRotateRight(
int n = 1)
const {
BitVector r(
size()); doRotateRight(n, r.bits);
return r; }
123 inline int item()
const {
return i; }
136 inline int item(
void)
const {
return i; }
147 inline bool get(
void)
const {
return _v.
bit(_i); }
152 inline operator bool(
void)
const {
return get(); }
178 inline BitVector& operator<<=(
int d) { shiftLeft(d);
return *
this; }
179 inline BitVector& operator>>=(
int d) { shiftRight(d);
return *
this; }
188 inline t::size __size(
void)
const {
return sizeof(*this) + wcount() *
sizeof(word_t); }
194 inline int wsize(
void)
const {
return sizeof(
word_t) << 3; }
195 inline int wshift(
void)
const {
return type_info<word_t>::shift + 3; }
196 inline int inWords(
int s)
const {
return (s + wsize() - 1) >> wshift(); }
197 inline int wcount(
void)
const {
return inWords(_size); }
198 inline int windex(
int index)
const {
return index >> wshift(); }
199 inline int bindex(
int index)
const {
return index & (wsize() - 1); }
201 inline void mask(word_t *bits)
const {
203 if(mask) bits[wcount() - 1] &=
mask;
205 inline void mask(
void)
const {
mask(bits); }
207 void doShiftLeft(
int n, word_t *tbits)
const;
208 void doShiftRight(
int n, word_t *tbits)
const;
209 void doRotateLeft(
int n, word_t *tbits)
const;
210 void doRotateRight(
int n, word_t *tbits)
const;
219 #endif // ELM_UTIL_BIT_VECTOR_H
BitVector operator&(const BitVector &vec) const
Definition: BitVector.h:165
bool operator<(const BitVector &vec) const
Definition: BitVector.h:183
Iter(const BitVector &v)
Definition: BitVector.h:101
Iter & operator++()
Definition: BitVector.h:109
int item() const
Definition: BitVector.h:123
typename type_info< T >::out_t out
Definition: type_info.h:284
void clear(int index) const
Definition: BitVector.h:64
int operator*() const
Definition: BitVector.h:138
~BitVector(void)
Definition: BitVector.h:38
OneIterator begin() const
Definition: BitVector.h:129
bool operator<=(const BitVector &vec) const
Definition: BitVector.h:184
void applyNot(void)
Definition: util_BitVector.cpp:229
BitVector & operator|=(const BitVector &vec)
Definition: BitVector.h:173
bool isEmpty(void) const
Definition: BitVector.h:46
bool operator*() const
Definition: BitVector.h:108
Ref & operator=(bool b)
Definition: BitVector.h:153
AutoString & operator<<(CString str, const T &value)
Definition: AutoString.h:75
BitVector & operator+=(const BitVector &vec)
Definition: BitVector.h:175
BitVector makeAnd(const BitVector &vec) const
Definition: util_BitVector.cpp:307
Definition: BitVector.h:144
void applyAnd(const BitVector &vec)
Definition: util_BitVector.cpp:253
bool get(void) const
Definition: BitVector.h:147
bool operator!=(const Iter &it) const
Definition: BitVector.h:112
Iter operator++(int)
Definition: BitVector.h:110
BitVector operator-(const BitVector &vec) const
Definition: BitVector.h:167
BitVector & operator=(const BitVector &vec)
Definition: util_BitVector.cpp:88
bool operator!=(const BitVector &vec) const
Definition: BitVector.h:182
ZeroIterator(const BitVector &bit_vector)
Definition: BitVector.h:135
void set(void)
Definition: BitVector.h:148
void next(void)
Definition: BitVector.h:137
bool ended() const
Definition: BitVector.h:102
OneIterator end() const
Definition: BitVector.h:130
void copy(const BitVector &bits) const
Definition: util_BitVector.cpp:211
OneIterator(const BitVector &bit_vector, int ii=0)
Definition: BitVector.h:122
int size(void) const
Definition: BitVector.h:39
void applyReset(const BitVector &vec)
Definition: util_BitVector.cpp:266
bool equals(const Iter &it) const
Definition: BitVector.h:105
Iter operator++(int)
Definition: BitVector.h:127
BitVector makeNot(void) const
Definition: util_BitVector.cpp:279
Ref(BitVector &v, int i)
Definition: BitVector.h:146
bool meets(const BitVector &bv)
Definition: util_BitVector.cpp:462
void applyOr(const BitVector &vec)
Definition: util_BitVector.cpp:241
bool operator==(const Iter &it) const
Definition: BitVector.h:111
bool bit(int i) const
Definition: BitVector.h:41
void clear(void)
Definition: util_BitVector.cpp:220
Iter & operator++()
Definition: BitVector.h:139
WAHVector::word_t word_t
Definition: util_WAHVector.cpp:29
void clear(void)
Definition: BitVector.h:149
int countZeroes(void) const
Definition: BitVector.h:97
void set(void)
Definition: util_BitVector.cpp:184
bool operator>(const BitVector &vec) const
Definition: BitVector.h:185
uint64 size
Definition: arch.h:35
Definition: BitVector.h:133
BitVector operator|(const BitVector &vec) const
Definition: BitVector.h:164
void set(int index) const
Definition: BitVector.h:60
Definition: BitVector.h:99
Iter operator++(int)
Definition: BitVector.h:140
void next()
Definition: BitVector.h:124
int i
Definition: BitVector.h:116
BitVector makeOr(const BitVector &vec) const
Definition: util_BitVector.cpp:292
BitVector & operator&=(const BitVector &vec)
Definition: BitVector.h:174
unsigned char uint8
Definition: arch.h:27
BitVector operator~(void) const
Definition: BitVector.h:163
bool includesStrictly(const BitVector &vec) const
Definition: util_BitVector.cpp:149
bool operator()() const
Definition: BitVector.h:107
BitVector operator+(const BitVector &vec) const
Definition: BitVector.h:166
int item(void) const
Definition: BitVector.h:136
Definition: BitVector.h:120
int operator*() const
Definition: BitVector.h:125
bool operator==(const BitVector &vec) const
Definition: BitVector.h:181
void print(io::Output &out) const
Definition: util_BitVector.cpp:437
bool operator>=(const BitVector &vec) const
Definition: BitVector.h:186
BitVector(void)
Definition: BitVector.h:34
bool equals(const BitVector &vec) const
Definition: util_BitVector.cpp:168
void set(bool b)
Definition: BitVector.h:150
Ref operator[](int i)
Definition: BitVector.h:162
t::size __size(void) const
Definition: BitVector.h:188
bool includes(const BitVector &vec) const
Definition: util_BitVector.cpp:134
int countOnes(void) const
Definition: util_BitVector.cpp:493
io::StringInput operator>>(const string &str, T &val)
Definition: AutoString.h:82
Definition: BitVector.h:31
BitVector makeReset(const BitVector &vec) const
Definition: util_BitVector.cpp:322
word_t mask(int n)
Definition: util_WAHVector.cpp:50
void resize(int new_size)
Definition: util_BitVector.cpp:512
void next()
Definition: BitVector.h:104
bool item() const
Definition: BitVector.h:103
bool operator[](int index) const
Definition: BitVector.h:161
void set(int index, bool value) const
Definition: BitVector.h:62
BitVector & operator-=(const BitVector &vec)
Definition: BitVector.h:176
int countBits(void) const
Definition: util_BitVector.cpp:449
const BitVector & bvec
Definition: BitVector.h:115
Iter & operator++()
Definition: BitVector.h:126