[Lemon-commits] [lemon_svn] alpar: r2348 - hugo/trunk/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:51:58 CET 2006
Author: alpar
Date: Wed Nov 16 14:19:05 2005
New Revision: 2348
Modified:
hugo/trunk/lemon/iterable_maps.h
Log:
Iterable Bool maps can count the number of true and false values.
Modified: hugo/trunk/lemon/iterable_maps.h
==============================================================================
--- hugo/trunk/lemon/iterable_maps.h (original)
+++ hugo/trunk/lemon/iterable_maps.h Wed Nov 16 14:19:05 2005
@@ -30,6 +30,7 @@
namespace lemon {
///\todo This is only a static map!
+ ///\todo Undocumented.
///\param BaseMap is an interger map.
template<class BaseMap>
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<int>::max()) { }
+ ///\e
FalseIt &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>=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<M.sep; }
};
@@ -122,7 +145,9 @@
}
if(init) sep=0;
}
+ ///\e
RefType operator[] (Key k) { return RefType(*this,k);}
+ ///\e
Value operator[] (Key k) const { return isTrue(k);}
};
@@ -163,6 +188,16 @@
public:
///\e
void set(Key k, bool v) { imap.set(k,v);}
+ ///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 imap.countTrue(); }
+ ///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 imap.countFalse(); }
#ifdef DOXYGEN
///\e
bool &operator[](Key k) { return imap[k];}
@@ -176,16 +211,20 @@
class FalseIt : public BimType::FalseIt
{
public:
+ ///\e
explicit FalseIt(const IterableBoolNodeMap &m)
: BimType::FalseIt(m.imap) { }
+ ///\e
FalseIt(Invalid i) : BimType::FalseIt(i) { }
};
///Iterator for the "true" nodes
class TrueIt : public BimType::TrueIt
{
public:
+ ///\e
explicit TrueIt(const IterableBoolNodeMap &m)
: BimType::TrueIt(m.imap) { }
+ ///\e
TrueIt(Invalid i) : BimType::TrueIt(i) { }
};
};
@@ -221,6 +260,14 @@
public:
///\e
void set(Key k, bool v) { imap.set(k,v);}
+ ///Returns the number of \c true values in the map.
+ ///This is a constant time operation.
+ int countTrue() { return imap.countTrue(); }
+ ///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 imap.countFalse(); }
#ifdef DOXYGEN
///\e
bool &operator[](Key k) { return imap[k];}
@@ -234,16 +281,20 @@
class FalseIt : public BimType::FalseIt
{
public:
+ ///\e
explicit FalseIt(const IterableBoolEdgeMap &m)
: BimType::FalseIt(m.imap) { }
+ ///\e
FalseIt(Invalid i) : BimType::FalseIt(i) { }
};
///Iterator for the "true" edges
class TrueIt : public BimType::TrueIt
{
public:
+ ///\e
explicit TrueIt(const IterableBoolEdgeMap &m)
: BimType::TrueIt(m.imap) { }
+ ///\e
TrueIt(Invalid i) : BimType::TrueIt(i) { }
};
};
More information about the Lemon-commits
mailing list