IterableBool{Upper/Lower}NodeMaps
authoralpar
Wed, 04 Jan 2006 13:19:12 +0000
changeset 1873d73c7f115f53
parent 1872 3b7694cf0a08
child 1874 396831fa7012
IterableBool{Upper/Lower}NodeMaps
lemon/iterable_maps.h
     1.1 --- a/lemon/iterable_maps.h	Wed Jan 04 11:41:58 2006 +0000
     1.2 +++ b/lemon/iterable_maps.h	Wed Jan 04 13:19:12 2006 +0000
     1.3 @@ -227,6 +227,150 @@
     1.4      };  
     1.5    };
     1.6  
     1.7 +  /// Iterable bool UpperNodeMap
     1.8 +
     1.9 +  /// This map can be used in the same way
    1.10 +  /// as the standard UpperNodeMap<bool> of the
    1.11 +  /// given graph \c Graph. 
    1.12 +  /// In addition, this class provides two iterators called \ref TrueIt
    1.13 +  /// and \ref FalseIt to iterate through the "true" and "false" nodes.
    1.14 +  template <class Graph>
    1.15 +  class IterableBoolUpperNodeMap
    1.16 +  {
    1.17 +    typename Graph::template UpperNodeMap<int> cmap;
    1.18 +  
    1.19 +  public:
    1.20 +  
    1.21 +    typedef IterableBoolMap<typename Graph::template UpperNodeMap<int> > BimType;
    1.22 +    BimType imap;
    1.23 +
    1.24 +
    1.25 +    typedef typename BimType::RefType RefType;
    1.26 +    typedef typename Graph::Node Key;
    1.27 +    typedef bool Value;
    1.28 +  
    1.29 +    friend class FalseIt;
    1.30 +    friend class TrueIt;
    1.31 +  
    1.32 +    ///\e
    1.33 +    IterableBoolUpperNodeMap(const Graph &g,bool b=false) : cmap(g), imap(cmap,b) {}
    1.34 +
    1.35 +  public:
    1.36 +    ///\e
    1.37 +    void set(Key k, bool v) { imap.set(k,v);}
    1.38 +    ///Number of \c true items in the map
    1.39 +
    1.40 +    ///Returns the number of \c true values in the map.
    1.41 +    ///This is a constant time operation.
    1.42 +    int countTrue() { return imap.countTrue(); }
    1.43 +    ///Number of \c false items in the map
    1.44 +
    1.45 +    ///Returns the number of \c false values in the map.
    1.46 +    ///This is a constant time operation.
    1.47 +    int countFalse() { return imap.countFalse(); }
    1.48 +#ifdef DOXYGEN
    1.49 +    ///\e
    1.50 +    bool &operator[](Key k) { return imap[k];}  
    1.51 +    ///\e
    1.52 +    const bool &operator[](Key k) const { return imap[k];}  
    1.53 +#else
    1.54 +    Value operator[](Key k) const { return imap[k];}  
    1.55 +    RefType operator[](Key k) { return imap[k];}  
    1.56 +#endif
    1.57 +    ///Iterator for the "false" nodes
    1.58 +    class FalseIt : public BimType::FalseIt
    1.59 +    {
    1.60 +    public:
    1.61 +      ///\e
    1.62 +      explicit FalseIt(const IterableBoolUpperNodeMap &m)
    1.63 +	: BimType::FalseIt(m.imap) { }
    1.64 +      ///\e
    1.65 +      FalseIt(Invalid i) : BimType::FalseIt(i) { }
    1.66 +    };
    1.67 +    ///Iterator for the "true" nodes
    1.68 +    class TrueIt : public BimType::TrueIt
    1.69 +    {
    1.70 +    public:
    1.71 +      ///\e
    1.72 +      explicit TrueIt(const IterableBoolUpperNodeMap &m)
    1.73 +	: BimType::TrueIt(m.imap) { }
    1.74 +      ///\e
    1.75 +      TrueIt(Invalid i) : BimType::TrueIt(i) { }
    1.76 +    };  
    1.77 +  };
    1.78 +
    1.79 +  /// Iterable bool LowerNodeMap
    1.80 +
    1.81 +  /// This map can be used in the same way
    1.82 +  /// as the standard LowerNodeMap<bool> of the
    1.83 +  /// given graph \c Graph. 
    1.84 +  /// In addition, this class provides two iterators called \ref TrueIt
    1.85 +  /// and \ref FalseIt to iterate through the "true" and "false" nodes.
    1.86 +  template <class Graph>
    1.87 +  class IterableBoolLowerNodeMap
    1.88 +  {
    1.89 +    typename Graph::template LowerNodeMap<int> cmap;
    1.90 +  
    1.91 +  public:
    1.92 +  
    1.93 +    typedef IterableBoolMap<typename Graph::template LowerNodeMap<int> > BimType;
    1.94 +    BimType imap;
    1.95 +
    1.96 +
    1.97 +    typedef typename BimType::RefType RefType;
    1.98 +    typedef typename Graph::Node Key;
    1.99 +    typedef bool Value;
   1.100 +  
   1.101 +    friend class FalseIt;
   1.102 +    friend class TrueIt;
   1.103 +  
   1.104 +    ///\e
   1.105 +    IterableBoolLowerNodeMap(const Graph &g,bool b=false) : cmap(g), imap(cmap,b) {}
   1.106 +
   1.107 +  public:
   1.108 +    ///\e
   1.109 +    void set(Key k, bool v) { imap.set(k,v);}
   1.110 +    ///Number of \c true items in the map
   1.111 +
   1.112 +    ///Returns the number of \c true values in the map.
   1.113 +    ///This is a constant time operation.
   1.114 +    int countTrue() { return imap.countTrue(); }
   1.115 +    ///Number of \c false items in the map
   1.116 +
   1.117 +    ///Returns the number of \c false values in the map.
   1.118 +    ///This is a constant time operation.
   1.119 +    int countFalse() { return imap.countFalse(); }
   1.120 +#ifdef DOXYGEN
   1.121 +    ///\e
   1.122 +    bool &operator[](Key k) { return imap[k];}  
   1.123 +    ///\e
   1.124 +    const bool &operator[](Key k) const { return imap[k];}  
   1.125 +#else
   1.126 +    Value operator[](Key k) const { return imap[k];}  
   1.127 +    RefType operator[](Key k) { return imap[k];}  
   1.128 +#endif
   1.129 +    ///Iterator for the "false" nodes
   1.130 +    class FalseIt : public BimType::FalseIt
   1.131 +    {
   1.132 +    public:
   1.133 +      ///\e
   1.134 +      explicit FalseIt(const IterableBoolLowerNodeMap &m)
   1.135 +	: BimType::FalseIt(m.imap) { }
   1.136 +      ///\e
   1.137 +      FalseIt(Invalid i) : BimType::FalseIt(i) { }
   1.138 +    };
   1.139 +    ///Iterator for the "true" nodes
   1.140 +    class TrueIt : public BimType::TrueIt
   1.141 +    {
   1.142 +    public:
   1.143 +      ///\e
   1.144 +      explicit TrueIt(const IterableBoolLowerNodeMap &m)
   1.145 +	: BimType::TrueIt(m.imap) { }
   1.146 +      ///\e
   1.147 +      TrueIt(Invalid i) : BimType::TrueIt(i) { }
   1.148 +    };  
   1.149 +  };
   1.150 +
   1.151    /// Iterable bool EdgeMap
   1.152  
   1.153    /// This map can be used in the same way