atlas
0.6
|
Traverses the set bits of a BitMap. More...
#include <bitmap.h>
Public Types | |
typedef std::forward_iterator_tag | iterator_category |
typedef unsigned long | value_type |
typedef ptrdiff_t | difference_type |
typedef const value_type * | pointer |
typedef const value_type & | reference |
Public Member Functions | |
iterator () | |
iterator (const iterator &j) | |
iterator (const std::vector< unsigned long >::const_iterator &p, unsigned long n, unsigned long c) | |
iterator & | operator= (const iterator &i) |
bool | operator== (const iterator &i) const |
bool | operator!= (const iterator &i) const |
bool | operator() () const |
const value_type & | operator* () const |
iterator & | operator++ () |
iterator | operator++ (int) |
void | change_owner (const BitMap &b) |
Private Attributes | |
std::vector< unsigned long >::const_iterator | d_chunk |
unsigned long | d_bitAddress |
unsigned long | d_capacity |
Traverses the set bits of a BitMap.
Because of the nature of a bitmap, only constant iterators make sense (just like for iterators into std::set); one cannot "change the value" of an element at a given position because the position is determined by the value (values are always increasing; in fact a small value-change could be realised by swapping a set bit with neighboring unset bits, but that is of course not what a non-constant iterator should allow doing). However, these iterators do allow changing the underlying bitmap during traversal, even though such changes cannot be performed using only the iterator itself (this is unlike iterators over a |bitset::BitSet|, which copy the set of bits into their own value and therefore will traverse the bits that were set at the time of their construction, usually by the |bitset::BitSet::begin| method).
The most delicate operation here is the increment, which has to find the position of the next set bit, while avoiding falling off the bitmap if there is no such. Therefore we included the data for the end of the bitmap in the iterator. This also allows the |operator()| internal test for exhaustion.
typedef ptrdiff_t atlas::bitmap::BitMap::iterator::difference_type |
typedef std::forward_iterator_tag atlas::bitmap::BitMap::iterator::iterator_category |
typedef const value_type* atlas::bitmap::BitMap::iterator::pointer |
typedef const value_type& atlas::bitmap::BitMap::iterator::reference |
typedef unsigned long atlas::bitmap::BitMap::iterator::value_type |
|
inline |
|
inline |
|
inline |
void atlas::bitmap::BitMap::iterator::change_owner | ( | const BitMap & | b | ) |
|
inline |
|
inline |
|
inline |
The incrementation operator; it has to move the bitAddress to the next set bit, and move the chunk if necessary.
This code below assumes that in case of an incomplete last chunk, there are no bits set in that chunk beyond the end of the bitmap; if there were, |firstBit(f)| below (both instances) could make the iterator advance to such a bit when it should have halted at |d_capacity|.
Post-increment operator; it should return the value as it was before the incrementation. This operator can mostly by avoided, as |M.remove(*it++)| can safely be replaced by |M.remove(*it),++it|
BitMap::iterator & atlas::bitmap::BitMap::iterator::operator= | ( | const iterator & | i | ) |
|
inline |
|
private |
|
private |
|
private |