# HG changeset patch # User alpar # Date 1136380752 0 # Node ID d73c7f115f53e9172c12c387d1e997bbd02186fa # Parent 3b7694cf0a080d3e47a490f124fcff5fa43f9a41 IterableBool{Upper/Lower}NodeMaps diff -r 3b7694cf0a08 -r d73c7f115f53 lemon/iterable_maps.h --- a/lemon/iterable_maps.h Wed Jan 04 11:41:58 2006 +0000 +++ b/lemon/iterable_maps.h Wed Jan 04 13:19:12 2006 +0000 @@ -227,6 +227,150 @@ }; }; + /// Iterable bool UpperNodeMap + + /// This map can be used in the same way + /// as the standard UpperNodeMap of the + /// given graph \c Graph. + /// In addition, this class provides two iterators called \ref TrueIt + /// and \ref FalseIt to iterate through the "true" and "false" nodes. + template + class IterableBoolUpperNodeMap + { + typename Graph::template UpperNodeMap cmap; + + public: + + typedef IterableBoolMap > BimType; + BimType imap; + + + typedef typename BimType::RefType RefType; + typedef typename Graph::Node Key; + typedef bool Value; + + friend class FalseIt; + friend class TrueIt; + + ///\e + IterableBoolUpperNodeMap(const Graph &g,bool b=false) : cmap(g), imap(cmap,b) {} + + 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];} + ///\e + const bool &operator[](Key k) const { return imap[k];} +#else + Value operator[](Key k) const { return imap[k];} + RefType operator[](Key k) { return imap[k];} +#endif + ///Iterator for the "false" nodes + class FalseIt : public BimType::FalseIt + { + public: + ///\e + explicit FalseIt(const IterableBoolUpperNodeMap &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 IterableBoolUpperNodeMap &m) + : BimType::TrueIt(m.imap) { } + ///\e + TrueIt(Invalid i) : BimType::TrueIt(i) { } + }; + }; + + /// Iterable bool LowerNodeMap + + /// This map can be used in the same way + /// as the standard LowerNodeMap of the + /// given graph \c Graph. + /// In addition, this class provides two iterators called \ref TrueIt + /// and \ref FalseIt to iterate through the "true" and "false" nodes. + template + class IterableBoolLowerNodeMap + { + typename Graph::template LowerNodeMap cmap; + + public: + + typedef IterableBoolMap > BimType; + BimType imap; + + + typedef typename BimType::RefType RefType; + typedef typename Graph::Node Key; + typedef bool Value; + + friend class FalseIt; + friend class TrueIt; + + ///\e + IterableBoolLowerNodeMap(const Graph &g,bool b=false) : cmap(g), imap(cmap,b) {} + + 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];} + ///\e + const bool &operator[](Key k) const { return imap[k];} +#else + Value operator[](Key k) const { return imap[k];} + RefType operator[](Key k) { return imap[k];} +#endif + ///Iterator for the "false" nodes + class FalseIt : public BimType::FalseIt + { + public: + ///\e + explicit FalseIt(const IterableBoolLowerNodeMap &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 IterableBoolLowerNodeMap &m) + : BimType::TrueIt(m.imap) { } + ///\e + TrueIt(Invalid i) : BimType::TrueIt(i) { } + }; + }; + /// Iterable bool EdgeMap /// This map can be used in the same way