Iterable Bool maps can count the number of true and false values.
1.1 --- a/lemon/iterable_maps.h Wed Nov 16 13:17:02 2005 +0000
1.2 +++ b/lemon/iterable_maps.h Wed Nov 16 13:19:05 2005 +0000
1.3 @@ -30,6 +30,7 @@
1.4 namespace lemon {
1.5
1.6 ///\todo This is only a static map!
1.7 + ///\todo Undocumented.
1.8 ///\param BaseMap is an interger map.
1.9 template<class BaseMap>
1.10 class IterableBoolMap
1.11 @@ -63,6 +64,16 @@
1.12 public:
1.13 ///\e
1.14 void set(Key k,Value v) { if(v) setTrue(k); else setFalse(k);}
1.15 + ///Number of \c true items in the map
1.16 +
1.17 + ///Returns the number of \c true values in the map.
1.18 + ///This is a constant time operation.
1.19 + int countTrue() { return vals.size()-sep; }
1.20 + ///Number of \c false items in the map
1.21 +
1.22 + ///Returns the number of \c false values in the map.
1.23 + ///This is a constant time operation.
1.24 + int countFalse() { return sep; }
1.25
1.26 ///\e
1.27 class FalseIt
1.28 @@ -70,12 +81,18 @@
1.29 const IterableBoolMap &M;
1.30 int i;
1.31 public:
1.32 + ///\e
1.33 explicit FalseIt(const IterableBoolMap &_M) : M(_M), i(0) { }
1.34 + ///\e
1.35 FalseIt(Invalid)
1.36 : M(*((IterableBoolMap*)(0))), i(std::numeric_limits<int>::max()) { }
1.37 + ///\e
1.38 FalseIt &operator++() { ++i; return *this;}
1.39 + ///\e
1.40 operator Key() const { return i<M.sep ? M.vals[i] : INVALID; }
1.41 + ///\e
1.42 bool operator !=(Invalid) const { return i<M.sep; }
1.43 + ///\e
1.44 bool operator ==(Invalid) const { return i>=M.sep; }
1.45 };
1.46 ///\e
1.47 @@ -84,13 +101,19 @@
1.48 const IterableBoolMap &M;
1.49 int i;
1.50 public:
1.51 + ///\e
1.52 explicit TrueIt(const IterableBoolMap &_M)
1.53 : M(_M), i(M.vals.size()-1) { }
1.54 + ///\e
1.55 TrueIt(Invalid)
1.56 : M(*((IterableBoolMap*)(0))), i(-1) { }
1.57 + ///\e
1.58 TrueIt &operator++() { --i; return *this;}
1.59 + ///\e
1.60 operator Key() const { return i>=M.sep ? M.vals[i] : INVALID; }
1.61 + ///\e
1.62 bool operator !=(Invalid) const { return i>=M.sep; }
1.63 + ///\e
1.64 bool operator ==(Invalid) const { return i<M.sep; }
1.65 };
1.66
1.67 @@ -122,7 +145,9 @@
1.68 }
1.69 if(init) sep=0;
1.70 }
1.71 + ///\e
1.72 RefType operator[] (Key k) { return RefType(*this,k);}
1.73 + ///\e
1.74 Value operator[] (Key k) const { return isTrue(k);}
1.75 };
1.76
1.77 @@ -163,6 +188,16 @@
1.78 public:
1.79 ///\e
1.80 void set(Key k, bool v) { imap.set(k,v);}
1.81 + ///Number of \c true items in the map
1.82 +
1.83 + ///Returns the number of \c true values in the map.
1.84 + ///This is a constant time operation.
1.85 + int countTrue() { return imap.countTrue(); }
1.86 + ///Number of \c false items in the map
1.87 +
1.88 + ///Returns the number of \c false values in the map.
1.89 + ///This is a constant time operation.
1.90 + int countFalse() { return imap.countFalse(); }
1.91 #ifdef DOXYGEN
1.92 ///\e
1.93 bool &operator[](Key k) { return imap[k];}
1.94 @@ -176,16 +211,20 @@
1.95 class FalseIt : public BimType::FalseIt
1.96 {
1.97 public:
1.98 + ///\e
1.99 explicit FalseIt(const IterableBoolNodeMap &m)
1.100 : BimType::FalseIt(m.imap) { }
1.101 + ///\e
1.102 FalseIt(Invalid i) : BimType::FalseIt(i) { }
1.103 };
1.104 ///Iterator for the "true" nodes
1.105 class TrueIt : public BimType::TrueIt
1.106 {
1.107 public:
1.108 + ///\e
1.109 explicit TrueIt(const IterableBoolNodeMap &m)
1.110 : BimType::TrueIt(m.imap) { }
1.111 + ///\e
1.112 TrueIt(Invalid i) : BimType::TrueIt(i) { }
1.113 };
1.114 };
1.115 @@ -221,6 +260,14 @@
1.116 public:
1.117 ///\e
1.118 void set(Key k, bool v) { imap.set(k,v);}
1.119 + ///Returns the number of \c true values in the map.
1.120 + ///This is a constant time operation.
1.121 + int countTrue() { return imap.countTrue(); }
1.122 + ///Number of \c false items in the map
1.123 +
1.124 + ///Returns the number of \c false values in the map.
1.125 + ///This is a constant time operation.
1.126 + int countFalse() { return imap.countFalse(); }
1.127 #ifdef DOXYGEN
1.128 ///\e
1.129 bool &operator[](Key k) { return imap[k];}
1.130 @@ -234,16 +281,20 @@
1.131 class FalseIt : public BimType::FalseIt
1.132 {
1.133 public:
1.134 + ///\e
1.135 explicit FalseIt(const IterableBoolEdgeMap &m)
1.136 : BimType::FalseIt(m.imap) { }
1.137 + ///\e
1.138 FalseIt(Invalid i) : BimType::FalseIt(i) { }
1.139 };
1.140 ///Iterator for the "true" edges
1.141 class TrueIt : public BimType::TrueIt
1.142 {
1.143 public:
1.144 + ///\e
1.145 explicit TrueIt(const IterableBoolEdgeMap &m)
1.146 : BimType::TrueIt(m.imap) { }
1.147 + ///\e
1.148 TrueIt(Invalid i) : BimType::TrueIt(i) { }
1.149 };
1.150 };