# HG changeset patch # User alpar # Date 1132147145 0 # Node ID d284f81f02a52ed95d92a7031575202a9b824248 # Parent 7a76e35e4a78fd174431c5b693392ad3987d259f Iterable Bool maps can count the number of true and false values. diff -r 7a76e35e4a78 -r d284f81f02a5 lemon/iterable_maps.h --- a/lemon/iterable_maps.h Wed Nov 16 13:17:02 2005 +0000 +++ b/lemon/iterable_maps.h Wed Nov 16 13:19:05 2005 +0000 @@ -30,6 +30,7 @@ namespace lemon { ///\todo This is only a static map! + ///\todo Undocumented. ///\param BaseMap is an interger map. template class IterableBoolMap @@ -63,6 +64,16 @@ public: ///\e void set(Key k,Value v) { if(v) setTrue(k); else setFalse(k);} + ///Number of \c true items in the map + + ///Returns the number of \c true values in the map. + ///This is a constant time operation. + int countTrue() { return vals.size()-sep; } + ///Number of \c false items in the map + + ///Returns the number of \c false values in the map. + ///This is a constant time operation. + int countFalse() { return sep; } ///\e class FalseIt @@ -70,12 +81,18 @@ const IterableBoolMap &M; int i; public: + ///\e explicit FalseIt(const IterableBoolMap &_M) : M(_M), i(0) { } + ///\e FalseIt(Invalid) : M(*((IterableBoolMap*)(0))), i(std::numeric_limits::max()) { } + ///\e FalseIt &operator++() { ++i; return *this;} + ///\e operator Key() const { return i=M.sep; } }; ///\e @@ -84,13 +101,19 @@ const IterableBoolMap &M; int i; public: + ///\e explicit TrueIt(const IterableBoolMap &_M) : M(_M), i(M.vals.size()-1) { } + ///\e TrueIt(Invalid) : M(*((IterableBoolMap*)(0))), i(-1) { } + ///\e TrueIt &operator++() { --i; return *this;} + ///\e operator Key() const { return i>=M.sep ? M.vals[i] : INVALID; } + ///\e bool operator !=(Invalid) const { return i>=M.sep; } + ///\e bool operator ==(Invalid) const { return i