|
Nemo
2.2.0
|
Non-template and faster implementation of std::bitset. More...
#include <bitstring.h>
Classes | |
| class | reference |
Public Types | |
| typedef unsigned long | _ul |
Public Member Functions | |
| bitstring (size_t length) | |
| bitstring (const bitstring &b) | |
| ~bitstring () | |
| _ul * | getword_atPos (size_t pos) |
| _ul * | getword_atIdx (size_t index) |
| size_t | size () |
| size_t | nb_words () |
| reference | operator[] (size_t pos) |
| bool | operator[] (size_t n) const |
| bitstring & | operator= (const bitstring &b) |
| bitstring & | operator&= (const bitstring &x) |
| bitstring & | operator|= (const bitstring &x) |
| bitstring & | operator^= (const bitstring &x) |
| bitstring | operator~ (void) |
| bitstring | operator& (const bitstring &x) |
| bitstring | operator| (const bitstring &x) |
| bitstring | operator^ (const bitstring &x) |
| unsigned int | local_popcountl (_ul wd) |
| Counts number of one's in string using a bit table count. | |
| unsigned int | count () |
| Count number of set bits. | |
| void | set (size_t n) |
| Set a bit to 1. | |
| void | flip (size_t n) |
| Flip the bit at n. | |
| void | set_data (_ul *srce, size_t nbwrd) |
| Copy bits from an array of unsigned long words. | |
| void | reset () |
| Set all bits to 0. | |
| void | copy (const bitstring &b) |
| Unchecked copy, assumes we have sames sizes. | |
| void | copy (const bitstring &b, size_t word_pos) |
| Copy one word. | |
| void | copy (const bitstring &b, size_t from, size_t to) |
Private Attributes | |
| size_t | _size |
| size_t | _words |
| _ul * | _data |
Static Private Attributes | |
| static unsigned char | _bit_count [256] |
Friends | |
| class | reference |
Non-template and faster implementation of std::bitset.
Definition at line 51 of file bitstring.h.
| typedef unsigned long bitstring::_ul |
Definition at line 55 of file bitstring.h.
| bitstring::bitstring | ( | size_t | length | ) | [inline] |
| bitstring::bitstring | ( | const bitstring & | b | ) | [inline] |
| bitstring::~bitstring | ( | ) | [inline] |
| void bitstring::copy | ( | const bitstring & | b | ) | [inline] |
Unchecked copy, assumes we have sames sizes.
Definition at line 249 of file bitstring.h.
Referenced by TTDeletMutations_bitstring::inherit_0(), TTDeletMutations_bitstring::operator=(), TTDeletMutations_bitstring::recombine(), and TTDeletMutations_bitstring::set_sequence().
| void bitstring::copy | ( | const bitstring & | b, |
| size_t | word_pos | ||
| ) | [inline] |
| void bitstring::copy | ( | const bitstring & | b, |
| size_t | from, | ||
| size_t | to | ||
| ) | [inline] |
Definition at line 256 of file bitstring.h.
References _data, _size, and BITS_PER_WORD.
{
assert(to <= _size);
size_t start_w, end_w, start_l, end_l;
_ul mask, tmpl;
start_w = from / BITS_PER_WORD;
end_w = to / BITS_PER_WORD;
start_l = from % BITS_PER_WORD;
end_l = to % BITS_PER_WORD;
if(start_w != end_w) {
//copy wihtin first word:
mask = (0xFFFFFFFF << start_l);
_data[ start_w ] &= ~mask;;
tmpl = b._data[ start_w ] & mask;
_data[ start_w ] |= tmpl;
//copy words in-between:
for(size_t k = start_w + 1; k < end_w; ++k) {
_data[ k ] = b._data[ k ];
}
//copy within last word:
mask = (0xFFFFFFFF >> (BITS_PER_WORD - end_l) );
_data[ end_w ] &= ~mask;;
tmpl = b._data[ end_w ] & mask;
_data[ end_w ] |= tmpl;
} else {
//bits to copy are within a word:
mask = (0xFFFFFFFF << start_l) & (0xFFFFFFFF >> (BITS_PER_WORD - end_l) );
_data[ start_w ] &= ~mask;
tmpl = b._data[ start_w ] & mask;
_data[ start_w ] |= tmpl;
}
}
| unsigned int bitstring::count | ( | ) | [inline] |
Count number of set bits.
Definition at line 219 of file bitstring.h.
References _data, _words, and local_popcountl().
Referenced by TTDeletMutations_bitstring::set_nb_hmz_mutations(), TTDeletMutations_bitstring::set_nb_htz_mutations(), and TTDeletMutations_bitstring::set_nb_mutations().
{
unsigned int cnt = 0;
for(size_t i = 0; i < _words; i++)
cnt += local_popcountl(_data[i]);
return cnt;
}
| void bitstring::flip | ( | size_t | n | ) | [inline] |
Flip the bit at n.
Definition at line 233 of file bitstring.h.
References _data, and BITS_PER_WORD.
{_data[n / BITS_PER_WORD] ^= (1UL << (n % BITS_PER_WORD));}
| _ul* bitstring::getword_atIdx | ( | size_t | index | ) | [inline] |
Definition at line 134 of file bitstring.h.
References _data.
Referenced by TTDeletMutations_bitstring::store_data().
{ return &_data[ index ]; }
| _ul* bitstring::getword_atPos | ( | size_t | pos | ) | [inline] |
Definition at line 131 of file bitstring.h.
References _data, and BITS_PER_WORD.
Referenced by bitstring::reference::reference().
{ return &_data[ pos / BITS_PER_WORD ]; }
| unsigned int bitstring::local_popcountl | ( | _ul | wd | ) | [inline] |
Counts number of one's in string using a bit table count.
Definition at line 207 of file bitstring.h.
References _bit_count.
Referenced by count().
{
unsigned char* c = (unsigned char*)&wd;
unsigned short cnt = 0;
for(unsigned int i = 0; i < sizeof(_ul); i++)
cnt += _bit_count[ (unsigned int)c[i] ];
return (unsigned int) cnt;
}
| size_t bitstring::nb_words | ( | ) | [inline] |
Definition at line 139 of file bitstring.h.
References _words.
Referenced by TTDeletMutations_bitstring::retrieve_data(), and TTDeletMutations_bitstring::store_data().
{return _words;}
Definition at line 185 of file bitstring.h.
{
bitstring result(*this);
result &= x;
return result;
}
| reference bitstring::operator[] | ( | size_t | pos | ) | [inline] |
| bool bitstring::operator[] | ( | size_t | n | ) | const [inline] |
Definition at line 144 of file bitstring.h.
References _data, and BITS_PER_WORD.
{ return static_cast<bool>( _data[ n / BITS_PER_WORD ] & ( 1UL << ( n % BITS_PER_WORD ) ) ); }
Definition at line 199 of file bitstring.h.
{
bitstring result(*this);
result ^= x;
return result;
}
Definition at line 192 of file bitstring.h.
{
bitstring result(*this);
result |= x;
return result;
}
| bitstring bitstring::operator~ | ( | void | ) | [inline] |
| void bitstring::reset | ( | ) | [inline] |
Set all bits to 0.
Definition at line 246 of file bitstring.h.
Referenced by TTDeletMutations_bitstring::init_sequence().
| void bitstring::set | ( | size_t | n | ) | [inline] |
Set a bit to 1.
Definition at line 230 of file bitstring.h.
References _data, and BITS_PER_WORD.
Referenced by TTDeletMutBitstrFH::FHread(), TTDeletMutations_bitstring::init_sequence(), TTDeletMutations_bitstring::mutate_noredraw(), and TTDeletMutations_bitstring::mutate_redraw().
{_data[n / BITS_PER_WORD] |= (1UL << (n % BITS_PER_WORD));}
| void bitstring::set_data | ( | _ul * | srce, |
| size_t | nbwrd | ||
| ) | [inline] |
Copy bits from an array of unsigned long words.
Definition at line 236 of file bitstring.h.
Referenced by TTDeletMutations_bitstring::retrieve_data().
| size_t bitstring::size | ( | ) | [inline] |
friend class reference [friend] |
Definition at line 113 of file bitstring.h.
Referenced by operator[]().
unsigned char bitstring::_bit_count [static, private] |
Definition at line 313 of file bitstring.h.
Referenced by local_popcountl().
_ul* bitstring::_data [private] |
Definition at line 310 of file bitstring.h.
Referenced by bitstring(), copy(), count(), flip(), getword_atIdx(), getword_atPos(), operator&=(), operator=(), operator[](), operator^=(), operator|=(), operator~(), reset(), set(), set_data(), and ~bitstring().
size_t bitstring::_size [private] |
Definition at line 307 of file bitstring.h.
Referenced by copy(), operator=(), and size().
size_t bitstring::_words [private] |
Definition at line 308 of file bitstring.h.
Referenced by bitstring(), copy(), count(), nb_words(), operator&=(), operator=(), operator^=(), operator|=(), operator~(), reset(), and set_data().
1.7.5.1 -- Nemo is hosted by