atlas  0.6
Public Types | Public Member Functions | Private Attributes | List of all members
atlas::bitmap::BitMap::iterator Class Reference

Traverses the set bits of a BitMap. More...

#include <bitmap.h>

Collaboration diagram for atlas::bitmap::BitMap::iterator:
Collaboration graph
[legend]

Public Types

typedef std::forward_iterator_tag iterator_category
 
typedef unsigned long value_type
 
typedef ptrdiff_t difference_type
 
typedef const value_typepointer
 
typedef const value_typereference
 

Public Member Functions

 iterator ()
 
 iterator (const iterator &j)
 
 iterator (const std::vector< unsigned long >::const_iterator &p, unsigned long n, unsigned long c)
 
iteratoroperator= (const iterator &i)
 
bool operator== (const iterator &i) const
 
bool operator!= (const iterator &i) const
 
bool operator() () const
 
const value_typeoperator* () const
 
iteratoroperator++ ()
 
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
 

Detailed Description

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.

Member Typedef Documentation

typedef std::forward_iterator_tag atlas::bitmap::BitMap::iterator::iterator_category

Constructor & Destructor Documentation

atlas::bitmap::BitMap::iterator::iterator ( )
inline
atlas::bitmap::BitMap::iterator::iterator ( const iterator j)
inline
atlas::bitmap::BitMap::iterator::iterator ( const std::vector< unsigned long >::const_iterator p,
unsigned long  n,
unsigned long  c 
)
inline

Member Function Documentation

void atlas::bitmap::BitMap::iterator::change_owner ( const BitMap b)
bool atlas::bitmap::BitMap::iterator::operator!= ( const iterator i) const
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|

bool atlas::bitmap::BitMap::iterator::operator== ( const iterator i) const
inline

Member Data Documentation

unsigned long atlas::bitmap::BitMap::iterator::d_bitAddress
private
unsigned long atlas::bitmap::BitMap::iterator::d_capacity
private
std::vector<unsigned long>::const_iterator atlas::bitmap::BitMap::iterator::d_chunk
private

The documentation for this class was generated from the following files: