#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 | 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 |
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, | |
| size_t | from, | |||
| size_t | to | |||
| ) | [inline] |
Definition at line 253 of file bitstring.h.
00254 { 00255 assert(to <= _size); 00256 00257 size_t start_w, end_w, start_l, end_l; 00258 _ul mask, tmpl; 00259 00260 start_w = from / BITS_PER_WORD; 00261 end_w = to / BITS_PER_WORD; 00262 00263 start_l = from % BITS_PER_WORD; 00264 end_l = to % BITS_PER_WORD; 00265 00266 if(start_w != end_w) { 00267 //copy wihtin first word: 00268 mask = (0xFFFFFFFF << start_l); 00269 00270 _data[ start_w ] &= ~mask;; 00271 tmpl = b._data[ start_w ] & mask; 00272 00273 _data[ start_w ] |= tmpl; 00274 00275 //copy words in-between: 00276 for(size_t k = start_w + 1; k < end_w; ++k) { 00277 00278 _data[ k ] = b._data[ k ]; 00279 00280 } 00281 //copy within last word: 00282 mask = (0xFFFFFFFF >> (BITS_PER_WORD - end_l) ); 00283 00284 _data[ end_w ] &= ~mask;; 00285 tmpl = b._data[ end_w ] & mask; 00286 00287 _data[ end_w ] |= tmpl; 00288 00289 } else { 00290 //bits to copy are within a word: 00291 mask = (0xFFFFFFFF << start_l) & (0xFFFFFFFF >> (BITS_PER_WORD - end_l) ); 00292 00293 _data[ start_w ] &= ~mask;; 00294 tmpl = b._data[ start_w ] & mask; 00295 00296 _data[ start_w ] |= tmpl; 00297 00298 } 00299 00300 }
| void bitstring::copy | ( | const bitstring & | b, | |
| size_t | word_pos | |||
| ) | [inline] |
| void bitstring::copy | ( | const bitstring & | b | ) | [inline] |
Unchecked copy, assumes we have sames sizes.
Definition at line 246 of file bitstring.h.
Referenced by TTDeletMutations_bitstring::inherit_0(), TTDeletMutations_bitstring::inherit_low(), TTDeletMutations_bitstring::operator=(), and TTDeletMutations_bitstring::set_sequence().
| unsigned int bitstring::count | ( | ) | [inline] |
Count number of set bits.
Definition at line 219 of file bitstring.h.
Referenced by TTDeletMutations_bitstring::set_nb_hmz_mutations(), TTDeletMutations_bitstring::set_nb_htz_mutations(), and TTDeletMutations_bitstring::set_nb_mutations().
00220 { 00221 unsigned int cnt = 0; 00222 00223 for(size_t i = 0; i < _words; i++) 00224 cnt += local_popcountl(_data[i]); 00225 00226 return cnt; 00227 }
| _ul* bitstring::getword_atIdx | ( | size_t | index | ) | [inline] |
Definition at line 134 of file bitstring.h.
Referenced by TTDeletMutations_bitstring::store_data().
00135 { return &_data[ index ]; }
| _ul* bitstring::getword_atPos | ( | size_t | pos | ) | [inline] |
Definition at line 131 of file bitstring.h.
Referenced by bitstring::bitstring::reference::reference().
00132 { 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.
Referenced by count().
00208 { 00209 unsigned char* c = (unsigned char*)&wd; 00210 unsigned short cnt = 0; 00211 00212 for(unsigned int i = 0; i < sizeof(_ul); i++) 00213 cnt += _bit_count[ (unsigned int)c[i] ]; 00214 00215 return (unsigned int) cnt; 00216 }
| size_t bitstring::nb_words | ( | ) | [inline] |
Definition at line 139 of file bitstring.h.
Referenced by TTDeletMutations_bitstring::retrieve_data(), and TTDeletMutations_bitstring::store_data().
00139 {return _words;}
Definition at line 185 of file bitstring.h.
00186 { 00187 bitstring result(*this); 00188 result &= x; 00189 return result; 00190 }
Definition at line 157 of file bitstring.h.
00158 { 00159 for (size_t i = 0; i < _words; i++) 00160 _data[i] &= x._data[i]; 00161 return *this; 00162 }
| bool bitstring::operator[] | ( | size_t | n | ) | const [inline] |
Definition at line 144 of file bitstring.h.
00145 { return static_cast<bool>( _data[ n / BITS_PER_WORD ] & ( 1UL << ( n % BITS_PER_WORD ) ) ); }
| reference bitstring::operator[] | ( | size_t | pos | ) | [inline] |
Definition at line 199 of file bitstring.h.
00200 { 00201 bitstring result(*this); 00202 result ^= x; 00203 return result; 00204 }
Definition at line 171 of file bitstring.h.
00172 { 00173 for (size_t i = 0; i < _words; i++) 00174 _data[i] ^= x._data[i]; 00175 return *this; 00176 }
Definition at line 192 of file bitstring.h.
00193 { 00194 bitstring result(*this); 00195 result |= x; 00196 return result; 00197 }
Definition at line 164 of file bitstring.h.
00165 { 00166 for (size_t i = 0; i < _words; i++) 00167 _data[i] |= x._data[i]; 00168 return *this; 00169 }
| bitstring bitstring::operator~ | ( | void | ) | [inline] |
Definition at line 178 of file bitstring.h.
00179 { 00180 for (size_t i = 0; i < _words; i++) 00181 _data[i] = ~(_data[i]); 00182 return *this; 00183 }
| void bitstring::reset | ( | ) | [inline] |
Set all bits to 0.
Definition at line 243 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.
Referenced by TTDeletMutBitstrFH::FHread(), TTDeletMutations_bitstring::init_sequence(), TTDeletMutations_bitstring::mutate_noredraw(), and TTDeletMutations_bitstring::mutate_redraw().
00230 {_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 233 of file bitstring.h.
Referenced by TTDeletMutations_bitstring::retrieve_data().
00234 { 00235 // if(nbwrd != _words) { 00236 // std::cerr<<"bitstring::set_data: different sizes in memcpy!!\n"; 00237 // exit(1); 00238 // } 00239 assert(nbwrd == _words); 00240 memcpy(_data, srce, nbwrd * sizeof(_ul)); 00241 }
| size_t bitstring::size | ( | ) | [inline] |
friend class reference [friend] |
unsigned char bitstring::_bit_count [static, private] |
_ul* bitstring::_data [private] |
Definition at line 307 of file bitstring.h.
Referenced by bitstring(), copy(), count(), getword_atIdx(), getword_atPos(), operator&=(), operator=(), operator[](), operator^=(), operator|=(), operator~(), reset(), set(), set_data(), and ~bitstring().
size_t bitstring::_size [private] |
size_t bitstring::_words [private] |
Definition at line 305 of file bitstring.h.
Referenced by bitstring(), copy(), count(), nb_words(), operator&=(), operator=(), operator^=(), operator|=(), operator~(), reset(), and set_data().
1.5.8 -- Nemo is hosted by