38 #ifdef _GLIBCPP_BITSET_BITS_PER_WORD
39 #define BITS_PER_WORD _GLIBCPP_BITSET_BITS_PER_WORD
41 #define BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
44 #ifndef _GLIBCPP_BITSET_WORDS
45 #define BITSET_WORDS(__n) \
46 ((__n) < 1 ? 1 : ((__n) + BITS_PER_WORD - 1)/BITS_PER_WORD)
48 #define BITSET_WORDS(__n) _GLIBCPP_BITSET_WORDS(__n)
52 #define MASK ULLONG_MAX
61 typedef unsigned long _ul;
108 operator bool()
const
156 {
return &
_data[ index ]; }
162 bool at (
size_t word,
unsigned long bitmask)
const
164 return bool(
_data[ word ] & bitmask );
185 for (
size_t i = 0; i <
_words; i++)
192 for (
size_t i = 0; i <
_words; i++)
199 for (
size_t i = 0; i <
_words; i++)
206 for (
size_t i = 0; i <
_words; i++)
235 unsigned char* c = (
unsigned char*)&wd;
236 unsigned short cnt = 0;
238 for(
unsigned int i = 0; i <
sizeof(
_ul); i++)
241 return (
unsigned int) cnt;
247 unsigned int cnt = 0;
249 for(
size_t i = 0; i <
_words; i++)
259 void set (
size_t n,
bool x) {
277 memcpy(
_data, srce, nbwrd *
sizeof(
_ul));
281 {
for(
unsigned int i = 0; i <
_words; i++)
_data[i] = 0UL; }
298 size_t start_w, end_w, start_l, end_l;
307 if(start_w != end_w) {
309 mask = (
MASK << start_l);
311 _data[ start_w ] &= ~mask;
312 tmpl = b.
_data[ start_w ] & mask;
314 _data[ start_w ] |= tmpl;
317 size_t k = start_w + 1;
324 _data[ end_w ] &= ~mask;;
325 tmpl = b.
_data[ end_w ] & mask;
327 _data[ end_w ] |= tmpl;
333 _data[ start_w ] &= ~mask;
334 tmpl = b.
_data[ start_w ] & mask;
336 _data[ start_w ] |= tmpl;
344 const char one =
'1';
347 result.assign(
_size,
'0');
349 for(
size_t i = 0; i <
_size; ++i) {
359 assert(from < to && to <
_size+1);
361 const char one =
'1';
363 size_t len = to - from;
367 result.assign(len,
'0');
369 for(
size_t i = from, s = 0; i < to && s < len; ++i, ++s) {
376 void print (
size_t from,
size_t to)
const
378 assert(from < to && to <
_size+1);
379 for(
unsigned int i = from; i < to; ++i)
381 std::cout<<std::endl;
386 for(
unsigned int i = 0; i <
_size; ++i)
388 std::cout<<std::endl;
#define BITSET_WORDS(__n)
Definition: bitstring.h:45
#define MASK
Definition: bitstring.h:52
#define BITS_PER_WORD
Definition: bitstring.h:41
Definition: bitstring.h:64
reference(bitstring &bs, size_t pos)
Definition: bitstring.h:74
reference & operator=(bool x)
Definition: bitstring.h:84
_ul * _word
Definition: bitstring.h:67
reference & flip()
Definition: bitstring.h:112
size_t _bitpos
Definition: bitstring.h:68
~reference()
Definition: bitstring.h:80
bool operator~() const
Definition: bitstring.h:104
reference & operator=(const reference &j)
Definition: bitstring.h:94
Non-template and faster implementation of std::bitset.
Definition: bitstring.h:57
static unsigned char _bit_count[256]
Definition: bitstring.h:402
bitstring(const bitstring &b)
Definition: bitstring.h:130
bitstring operator|(const bitstring &x)
Definition: bitstring.h:218
unsigned int count()
Count number of set bits.
Definition: bitstring.h:245
bool at(size_t word, unsigned long bitmask) const
Definition: bitstring.h:162
_ul * getword_atPos(size_t pos) const
Definition: bitstring.h:152
unsigned long _ul
Definition: bitstring.h:61
bitstring()
Definition: bitstring.h:121
size_t size() const
Definition: bitstring.h:158
_ul * getword_atIdx(size_t index) const
Definition: bitstring.h:155
size_t _words
Number of _ul-long Words necessary to hold the _size bits.
Definition: bitstring.h:396
void print(size_t from, size_t to) const
Definition: bitstring.h:376
bitstring operator&(const bitstring &x)
Definition: bitstring.h:211
bitstring & operator|=(const bitstring &x)
Definition: bitstring.h:190
std::string to_string() const
Definition: bitstring.h:342
reference operator[](size_t pos)
Definition: bitstring.h:167
unsigned int local_popcountl(_ul wd)
Counts number of one's in string using a bit table count.
Definition: bitstring.h:233
void set(size_t n, bool x)
Set a bit to 0 or 1.
Definition: bitstring.h:259
void reset()
Set all bits to 0.
Definition: bitstring.h:280
bitstring & operator=(const bitstring &b)
Definition: bitstring.h:173
bitstring & operator^=(const bitstring &x)
Definition: bitstring.h:197
friend class reference
Definition: bitstring.h:119
void set(size_t n)
Set a bit to 1.
Definition: bitstring.h:256
bitstring operator~(void)
Definition: bitstring.h:204
size_t _size
Number of bits in the sequence.
Definition: bitstring.h:393
_ul * _data
The sequence.
Definition: bitstring.h:399
~bitstring()
Definition: bitstring.h:137
void set_data(_ul *srce, size_t nbwrd)
Copy bits from an array of unsigned long words.
Definition: bitstring.h:270
std::string to_string(size_t from, size_t to) const
Definition: bitstring.h:357
void flip(size_t n)
Flip the bit at n.
Definition: bitstring.h:267
void print() const
Definition: bitstring.h:384
bitstring operator^(const bitstring &x)
Definition: bitstring.h:225
void copy(const bitstring &b, size_t word_pos)
Copy one word.
Definition: bitstring.h:288
bitstring & operator&=(const bitstring &x)
Definition: bitstring.h:183
bitstring(size_t length)
Definition: bitstring.h:123
void copy(const bitstring &b)
Unchecked copy, assumes we have sames sizes.
Definition: bitstring.h:284
void copy(const bitstring &b, size_t from, size_t to)
Copy a delimited sequence block.
Definition: bitstring.h:292
size_t nb_words() const
Definition: bitstring.h:160
void reset(size_t length)
Definition: bitstring.h:140