lemon/maps.h
changeset 783 ef88c0a30f85
parent 725 11404088d1a5
parent 717 684964884a2e
child 786 e20173729589
child 789 8ddb7deabab9
     1.1 --- a/lemon/maps.h	Mon Jan 12 23:11:39 2009 +0100
     1.2 +++ b/lemon/maps.h	Thu Nov 05 15:48:01 2009 +0100
     1.3 @@ -22,6 +22,7 @@
     1.4  #include <iterator>
     1.5  #include <functional>
     1.6  #include <vector>
     1.7 +#include <map>
     1.8  
     1.9  #include <lemon/core.h>
    1.10  
    1.11 @@ -29,8 +30,6 @@
    1.12  ///\ingroup maps
    1.13  ///\brief Miscellaneous property maps
    1.14  
    1.15 -#include <map>
    1.16 -
    1.17  namespace lemon {
    1.18  
    1.19    /// \addtogroup maps
    1.20 @@ -57,15 +56,16 @@
    1.21    /// its type definitions, or if you have to provide a writable map,
    1.22    /// but data written to it is not required (i.e. it will be sent to
    1.23    /// <tt>/dev/null</tt>).
    1.24 -  /// It conforms the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    1.25 +  /// It conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
    1.26    ///
    1.27    /// \sa ConstMap
    1.28    template<typename K, typename V>
    1.29    class NullMap : public MapBase<K, V> {
    1.30    public:
    1.31 -    typedef MapBase<K, V> Parent;
    1.32 -    typedef typename Parent::Key Key;
    1.33 -    typedef typename Parent::Value Value;
    1.34 +    ///\e
    1.35 +    typedef K Key;
    1.36 +    ///\e
    1.37 +    typedef V Value;
    1.38  
    1.39      /// Gives back a default constructed element.
    1.40      Value operator[](const Key&) const { return Value(); }
    1.41 @@ -89,7 +89,7 @@
    1.42    /// value to each key.
    1.43    ///
    1.44    /// In other aspects it is equivalent to \c NullMap.
    1.45 -  /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
    1.46 +  /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap"
    1.47    /// concept, but it absorbs the data written to it.
    1.48    ///
    1.49    /// The simplest way of using this map is through the constMap()
    1.50 @@ -102,9 +102,10 @@
    1.51    private:
    1.52      V _value;
    1.53    public:
    1.54 -    typedef MapBase<K, V> Parent;
    1.55 -    typedef typename Parent::Key Key;
    1.56 -    typedef typename Parent::Value Value;
    1.57 +    ///\e
    1.58 +    typedef K Key;
    1.59 +    ///\e
    1.60 +    typedef V Value;
    1.61  
    1.62      /// Default constructor
    1.63  
    1.64 @@ -157,7 +158,7 @@
    1.65    /// value to each key.
    1.66    ///
    1.67    /// In other aspects it is equivalent to \c NullMap.
    1.68 -  /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
    1.69 +  /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap"
    1.70    /// concept, but it absorbs the data written to it.
    1.71    ///
    1.72    /// The simplest way of using this map is through the constMap()
    1.73 @@ -168,9 +169,10 @@
    1.74    template<typename K, typename V, V v>
    1.75    class ConstMap<K, Const<V, v> > : public MapBase<K, V> {
    1.76    public:
    1.77 -    typedef MapBase<K, V> Parent;
    1.78 -    typedef typename Parent::Key Key;
    1.79 -    typedef typename Parent::Value Value;
    1.80 +    ///\e
    1.81 +    typedef K Key;
    1.82 +    ///\e
    1.83 +    typedef V Value;
    1.84  
    1.85      /// Constructor.
    1.86      ConstMap() {}
    1.87 @@ -202,9 +204,10 @@
    1.88    template <typename T>
    1.89    class IdentityMap : public MapBase<T, T> {
    1.90    public:
    1.91 -    typedef MapBase<T, T> Parent;
    1.92 -    typedef typename Parent::Key Key;
    1.93 -    typedef typename Parent::Value Value;
    1.94 +    ///\e
    1.95 +    typedef T Key;
    1.96 +    ///\e
    1.97 +    typedef T Value;
    1.98  
    1.99      /// Gives back the given value without any modification.
   1.100      Value operator[](const Key &k) const {
   1.101 @@ -229,7 +232,7 @@
   1.102    /// values to integer keys from the range <tt>[0..size-1]</tt>.
   1.103    /// It can be used with some data structures, for example
   1.104    /// \c UnionFind, \c BinHeap, when the used items are small
   1.105 -  /// integers. This map conforms the \ref concepts::ReferenceMap
   1.106 +  /// integers. This map conforms to the \ref concepts::ReferenceMap
   1.107    /// "ReferenceMap" concept.
   1.108    ///
   1.109    /// The simplest way of using this map is through the rangeMap()
   1.110 @@ -245,11 +248,10 @@
   1.111  
   1.112    public:
   1.113  
   1.114 -    typedef MapBase<int, V> Parent;
   1.115      /// Key type
   1.116 -    typedef typename Parent::Key Key;
   1.117 +    typedef int Key;
   1.118      /// Value type
   1.119 -    typedef typename Parent::Value Value;
   1.120 +    typedef V Value;
   1.121      /// Reference type
   1.122      typedef typename Vector::reference Reference;
   1.123      /// Const reference type
   1.124 @@ -338,7 +340,7 @@
   1.125    /// that you can specify a default value for the keys that are not
   1.126    /// stored actually. This value can be different from the default
   1.127    /// contructed value (i.e. \c %Value()).
   1.128 -  /// This type conforms the \ref concepts::ReferenceMap "ReferenceMap"
   1.129 +  /// This type conforms to the \ref concepts::ReferenceMap "ReferenceMap"
   1.130    /// concept.
   1.131    ///
   1.132    /// This map is useful if a default value should be assigned to most of
   1.133 @@ -353,17 +355,16 @@
   1.134    ///
   1.135    /// The simplest way of using this map is through the sparseMap()
   1.136    /// function.
   1.137 -  template <typename K, typename V, typename Compare = std::less<K> >
   1.138 +  template <typename K, typename V, typename Comp = std::less<K> >
   1.139    class SparseMap : public MapBase<K, V> {
   1.140      template <typename K1, typename V1, typename C1>
   1.141      friend class SparseMap;
   1.142    public:
   1.143  
   1.144 -    typedef MapBase<K, V> Parent;
   1.145      /// Key type
   1.146 -    typedef typename Parent::Key Key;
   1.147 +    typedef K Key;
   1.148      /// Value type
   1.149 -    typedef typename Parent::Value Value;
   1.150 +    typedef V Value;
   1.151      /// Reference type
   1.152      typedef Value& Reference;
   1.153      /// Const reference type
   1.154 @@ -373,7 +374,7 @@
   1.155  
   1.156    private:
   1.157  
   1.158 -    typedef std::map<K, V, Compare> Map;
   1.159 +    typedef std::map<K, V, Comp> Map;
   1.160      Map _map;
   1.161      Value _value;
   1.162  
   1.163 @@ -489,14 +490,15 @@
   1.164      const M1 &_m1;
   1.165      const M2 &_m2;
   1.166    public:
   1.167 -    typedef MapBase<typename M2::Key, typename M1::Value> Parent;
   1.168 -    typedef typename Parent::Key Key;
   1.169 -    typedef typename Parent::Value Value;
   1.170 +    ///\e
   1.171 +    typedef typename M2::Key Key;
   1.172 +    ///\e
   1.173 +    typedef typename M1::Value Value;
   1.174  
   1.175      /// Constructor
   1.176      ComposeMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
   1.177  
   1.178 -    /// \e
   1.179 +    ///\e
   1.180      typename MapTraits<M1>::ConstReturnValue
   1.181      operator[](const Key &k) const { return _m1[_m2[k]]; }
   1.182    };
   1.183 @@ -545,14 +547,15 @@
   1.184      const M2 &_m2;
   1.185      F _f;
   1.186    public:
   1.187 -    typedef MapBase<typename M1::Key, V> Parent;
   1.188 -    typedef typename Parent::Key Key;
   1.189 -    typedef typename Parent::Value Value;
   1.190 +    ///\e
   1.191 +    typedef typename M1::Key Key;
   1.192 +    ///\e
   1.193 +    typedef V Value;
   1.194  
   1.195      /// Constructor
   1.196      CombineMap(const M1 &m1, const M2 &m2, const F &f = F())
   1.197        : _m1(m1), _m2(m2), _f(f) {}
   1.198 -    /// \e
   1.199 +    ///\e
   1.200      Value operator[](const Key &k) const { return _f(_m1[k],_m2[k]); }
   1.201    };
   1.202  
   1.203 @@ -615,13 +618,14 @@
   1.204    class FunctorToMap : public MapBase<K, V> {
   1.205      F _f;
   1.206    public:
   1.207 -    typedef MapBase<K, V> Parent;
   1.208 -    typedef typename Parent::Key Key;
   1.209 -    typedef typename Parent::Value Value;
   1.210 +    ///\e
   1.211 +    typedef K Key;
   1.212 +    ///\e
   1.213 +    typedef V Value;
   1.214  
   1.215      /// Constructor
   1.216      FunctorToMap(const F &f = F()) : _f(f) {}
   1.217 -    /// \e
   1.218 +    ///\e
   1.219      Value operator[](const Key &k) const { return _f(k); }
   1.220    };
   1.221  
   1.222 @@ -669,18 +673,19 @@
   1.223    class MapToFunctor : public MapBase<typename M::Key, typename M::Value> {
   1.224      const M &_m;
   1.225    public:
   1.226 -    typedef MapBase<typename M::Key, typename M::Value> Parent;
   1.227 -    typedef typename Parent::Key Key;
   1.228 -    typedef typename Parent::Value Value;
   1.229 -
   1.230 -    typedef typename Parent::Key argument_type;
   1.231 -    typedef typename Parent::Value result_type;
   1.232 +    ///\e
   1.233 +    typedef typename M::Key Key;
   1.234 +    ///\e
   1.235 +    typedef typename M::Value Value;
   1.236 +
   1.237 +    typedef typename M::Key argument_type;
   1.238 +    typedef typename M::Value result_type;
   1.239  
   1.240      /// Constructor
   1.241      MapToFunctor(const M &m) : _m(m) {}
   1.242 -    /// \e
   1.243 +    ///\e
   1.244      Value operator()(const Key &k) const { return _m[k]; }
   1.245 -    /// \e
   1.246 +    ///\e
   1.247      Value operator[](const Key &k) const { return _m[k]; }
   1.248    };
   1.249  
   1.250 @@ -701,7 +706,7 @@
   1.251    /// "readable map" to another type using the default conversion.
   1.252    /// The \c Key type of it is inherited from \c M and the \c Value
   1.253    /// type is \c V.
   1.254 -  /// This type conforms the \ref concepts::ReadMap "ReadMap" concept.
   1.255 +  /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
   1.256    ///
   1.257    /// The simplest way of using this map is through the convertMap()
   1.258    /// function.
   1.259 @@ -709,9 +714,10 @@
   1.260    class ConvertMap : public MapBase<typename M::Key, V> {
   1.261      const M &_m;
   1.262    public:
   1.263 -    typedef MapBase<typename M::Key, V> Parent;
   1.264 -    typedef typename Parent::Key Key;
   1.265 -    typedef typename Parent::Value Value;
   1.266 +    ///\e
   1.267 +    typedef typename M::Key Key;
   1.268 +    ///\e
   1.269 +    typedef V Value;
   1.270  
   1.271      /// Constructor
   1.272  
   1.273 @@ -719,7 +725,7 @@
   1.274      /// \param m The underlying map.
   1.275      ConvertMap(const M &m) : _m(m) {}
   1.276  
   1.277 -    /// \e
   1.278 +    ///\e
   1.279      Value operator[](const Key &k) const { return _m[k]; }
   1.280    };
   1.281  
   1.282 @@ -751,9 +757,10 @@
   1.283      M1 &_m1;
   1.284      M2 &_m2;
   1.285    public:
   1.286 -    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
   1.287 -    typedef typename Parent::Key Key;
   1.288 -    typedef typename Parent::Value Value;
   1.289 +    ///\e
   1.290 +    typedef typename M1::Key Key;
   1.291 +    ///\e
   1.292 +    typedef typename M1::Value Value;
   1.293  
   1.294      /// Constructor
   1.295      ForkMap(M1 &m1, M2 &m2) : _m1(m1), _m2(m2) {}
   1.296 @@ -797,13 +804,14 @@
   1.297      const M1 &_m1;
   1.298      const M2 &_m2;
   1.299    public:
   1.300 -    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
   1.301 -    typedef typename Parent::Key Key;
   1.302 -    typedef typename Parent::Value Value;
   1.303 +    ///\e
   1.304 +    typedef typename M1::Key Key;
   1.305 +    ///\e
   1.306 +    typedef typename M1::Value Value;
   1.307  
   1.308      /// Constructor
   1.309      AddMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
   1.310 -    /// \e
   1.311 +    ///\e
   1.312      Value operator[](const Key &k) const { return _m1[k]+_m2[k]; }
   1.313    };
   1.314  
   1.315 @@ -845,13 +853,14 @@
   1.316      const M1 &_m1;
   1.317      const M2 &_m2;
   1.318    public:
   1.319 -    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
   1.320 -    typedef typename Parent::Key Key;
   1.321 -    typedef typename Parent::Value Value;
   1.322 +    ///\e
   1.323 +    typedef typename M1::Key Key;
   1.324 +    ///\e
   1.325 +    typedef typename M1::Value Value;
   1.326  
   1.327      /// Constructor
   1.328      SubMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
   1.329 -    /// \e
   1.330 +    ///\e
   1.331      Value operator[](const Key &k) const { return _m1[k]-_m2[k]; }
   1.332    };
   1.333  
   1.334 @@ -894,13 +903,14 @@
   1.335      const M1 &_m1;
   1.336      const M2 &_m2;
   1.337    public:
   1.338 -    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
   1.339 -    typedef typename Parent::Key Key;
   1.340 -    typedef typename Parent::Value Value;
   1.341 +    ///\e
   1.342 +    typedef typename M1::Key Key;
   1.343 +    ///\e
   1.344 +    typedef typename M1::Value Value;
   1.345  
   1.346      /// Constructor
   1.347      MulMap(const M1 &m1,const M2 &m2) : _m1(m1), _m2(m2) {}
   1.348 -    /// \e
   1.349 +    ///\e
   1.350      Value operator[](const Key &k) const { return _m1[k]*_m2[k]; }
   1.351    };
   1.352  
   1.353 @@ -942,13 +952,14 @@
   1.354      const M1 &_m1;
   1.355      const M2 &_m2;
   1.356    public:
   1.357 -    typedef MapBase<typename M1::Key, typename M1::Value> Parent;
   1.358 -    typedef typename Parent::Key Key;
   1.359 -    typedef typename Parent::Value Value;
   1.360 +    ///\e
   1.361 +    typedef typename M1::Key Key;
   1.362 +    ///\e
   1.363 +    typedef typename M1::Value Value;
   1.364  
   1.365      /// Constructor
   1.366      DivMap(const M1 &m1,const M2 &m2) : _m1(m1), _m2(m2) {}
   1.367 -    /// \e
   1.368 +    ///\e
   1.369      Value operator[](const Key &k) const { return _m1[k]/_m2[k]; }
   1.370    };
   1.371  
   1.372 @@ -992,9 +1003,10 @@
   1.373      const M &_m;
   1.374      C _v;
   1.375    public:
   1.376 -    typedef MapBase<typename M::Key, typename M::Value> Parent;
   1.377 -    typedef typename Parent::Key Key;
   1.378 -    typedef typename Parent::Value Value;
   1.379 +    ///\e
   1.380 +    typedef typename M::Key Key;
   1.381 +    ///\e
   1.382 +    typedef typename M::Value Value;
   1.383  
   1.384      /// Constructor
   1.385  
   1.386 @@ -1002,7 +1014,7 @@
   1.387      /// \param m The undelying map.
   1.388      /// \param v The constant value.
   1.389      ShiftMap(const M &m, const C &v) : _m(m), _v(v) {}
   1.390 -    /// \e
   1.391 +    ///\e
   1.392      Value operator[](const Key &k) const { return _m[k]+_v; }
   1.393    };
   1.394  
   1.395 @@ -1022,9 +1034,10 @@
   1.396      M &_m;
   1.397      C _v;
   1.398    public:
   1.399 -    typedef MapBase<typename M::Key, typename M::Value> Parent;
   1.400 -    typedef typename Parent::Key Key;
   1.401 -    typedef typename Parent::Value Value;
   1.402 +    ///\e
   1.403 +    typedef typename M::Key Key;
   1.404 +    ///\e
   1.405 +    typedef typename M::Value Value;
   1.406  
   1.407      /// Constructor
   1.408  
   1.409 @@ -1032,9 +1045,9 @@
   1.410      /// \param m The undelying map.
   1.411      /// \param v The constant value.
   1.412      ShiftWriteMap(M &m, const C &v) : _m(m), _v(v) {}
   1.413 -    /// \e
   1.414 +    ///\e
   1.415      Value operator[](const Key &k) const { return _m[k]+_v; }
   1.416 -    /// \e
   1.417 +    ///\e
   1.418      void set(const Key &k, const Value &v) { _m.set(k, v-_v); }
   1.419    };
   1.420  
   1.421 @@ -1093,9 +1106,10 @@
   1.422      const M &_m;
   1.423      C _v;
   1.424    public:
   1.425 -    typedef MapBase<typename M::Key, typename M::Value> Parent;
   1.426 -    typedef typename Parent::Key Key;
   1.427 -    typedef typename Parent::Value Value;
   1.428 +    ///\e
   1.429 +    typedef typename M::Key Key;
   1.430 +    ///\e
   1.431 +    typedef typename M::Value Value;
   1.432  
   1.433      /// Constructor
   1.434  
   1.435 @@ -1103,7 +1117,7 @@
   1.436      /// \param m The undelying map.
   1.437      /// \param v The constant value.
   1.438      ScaleMap(const M &m, const C &v) : _m(m), _v(v) {}
   1.439 -    /// \e
   1.440 +    ///\e
   1.441      Value operator[](const Key &k) const { return _v*_m[k]; }
   1.442    };
   1.443  
   1.444 @@ -1124,9 +1138,10 @@
   1.445      M &_m;
   1.446      C _v;
   1.447    public:
   1.448 -    typedef MapBase<typename M::Key, typename M::Value> Parent;
   1.449 -    typedef typename Parent::Key Key;
   1.450 -    typedef typename Parent::Value Value;
   1.451 +    ///\e
   1.452 +    typedef typename M::Key Key;
   1.453 +    ///\e
   1.454 +    typedef typename M::Value Value;
   1.455  
   1.456      /// Constructor
   1.457  
   1.458 @@ -1134,9 +1149,9 @@
   1.459      /// \param m The undelying map.
   1.460      /// \param v The constant value.
   1.461      ScaleWriteMap(M &m, const C &v) : _m(m), _v(v) {}
   1.462 -    /// \e
   1.463 +    ///\e
   1.464      Value operator[](const Key &k) const { return _v*_m[k]; }
   1.465 -    /// \e
   1.466 +    ///\e
   1.467      void set(const Key &k, const Value &v) { _m.set(k, v/_v); }
   1.468    };
   1.469  
   1.470 @@ -1193,13 +1208,14 @@
   1.471    class NegMap : public MapBase<typename M::Key, typename M::Value> {
   1.472      const M& _m;
   1.473    public:
   1.474 -    typedef MapBase<typename M::Key, typename M::Value> Parent;
   1.475 -    typedef typename Parent::Key Key;
   1.476 -    typedef typename Parent::Value Value;
   1.477 +    ///\e
   1.478 +    typedef typename M::Key Key;
   1.479 +    ///\e
   1.480 +    typedef typename M::Value Value;
   1.481  
   1.482      /// Constructor
   1.483      NegMap(const M &m) : _m(m) {}
   1.484 -    /// \e
   1.485 +    ///\e
   1.486      Value operator[](const Key &k) const { return -_m[k]; }
   1.487    };
   1.488  
   1.489 @@ -1228,15 +1244,16 @@
   1.490    class NegWriteMap : public MapBase<typename M::Key, typename M::Value> {
   1.491      M &_m;
   1.492    public:
   1.493 -    typedef MapBase<typename M::Key, typename M::Value> Parent;
   1.494 -    typedef typename Parent::Key Key;
   1.495 -    typedef typename Parent::Value Value;
   1.496 +    ///\e
   1.497 +    typedef typename M::Key Key;
   1.498 +    ///\e
   1.499 +    typedef typename M::Value Value;
   1.500  
   1.501      /// Constructor
   1.502      NegWriteMap(M &m) : _m(m) {}
   1.503 -    /// \e
   1.504 +    ///\e
   1.505      Value operator[](const Key &k) const { return -_m[k]; }
   1.506 -    /// \e
   1.507 +    ///\e
   1.508      void set(const Key &k, const Value &v) { _m.set(k, -v); }
   1.509    };
   1.510  
   1.511 @@ -1282,13 +1299,14 @@
   1.512    class AbsMap : public MapBase<typename M::Key, typename M::Value> {
   1.513      const M &_m;
   1.514    public:
   1.515 -    typedef MapBase<typename M::Key, typename M::Value> Parent;
   1.516 -    typedef typename Parent::Key Key;
   1.517 -    typedef typename Parent::Value Value;
   1.518 +    ///\e
   1.519 +    typedef typename M::Key Key;
   1.520 +    ///\e
   1.521 +    typedef typename M::Value Value;
   1.522  
   1.523      /// Constructor
   1.524      AbsMap(const M &m) : _m(m) {}
   1.525 -    /// \e
   1.526 +    ///\e
   1.527      Value operator[](const Key &k) const {
   1.528        Value tmp = _m[k];
   1.529        return tmp >= 0 ? tmp : -tmp;
   1.530 @@ -1337,9 +1355,10 @@
   1.531    template <typename K>
   1.532    class TrueMap : public MapBase<K, bool> {
   1.533    public:
   1.534 -    typedef MapBase<K, bool> Parent;
   1.535 -    typedef typename Parent::Key Key;
   1.536 -    typedef typename Parent::Value Value;
   1.537 +    ///\e
   1.538 +    typedef K Key;
   1.539 +    ///\e
   1.540 +    typedef bool Value;
   1.541  
   1.542      /// Gives back \c true.
   1.543      Value operator[](const Key&) const { return true; }
   1.544 @@ -1374,9 +1393,10 @@
   1.545    template <typename K>
   1.546    class FalseMap : public MapBase<K, bool> {
   1.547    public:
   1.548 -    typedef MapBase<K, bool> Parent;
   1.549 -    typedef typename Parent::Key Key;
   1.550 -    typedef typename Parent::Value Value;
   1.551 +    ///\e
   1.552 +    typedef K Key;
   1.553 +    ///\e
   1.554 +    typedef bool Value;
   1.555  
   1.556      /// Gives back \c false.
   1.557      Value operator[](const Key&) const { return false; }
   1.558 @@ -1419,13 +1439,14 @@
   1.559      const M1 &_m1;
   1.560      const M2 &_m2;
   1.561    public:
   1.562 -    typedef MapBase<typename M1::Key, bool> Parent;
   1.563 -    typedef typename Parent::Key Key;
   1.564 -    typedef typename Parent::Value Value;
   1.565 +    ///\e
   1.566 +    typedef typename M1::Key Key;
   1.567 +    ///\e
   1.568 +    typedef bool Value;
   1.569  
   1.570      /// Constructor
   1.571      AndMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
   1.572 -    /// \e
   1.573 +    ///\e
   1.574      Value operator[](const Key &k) const { return _m1[k]&&_m2[k]; }
   1.575    };
   1.576  
   1.577 @@ -1467,13 +1488,14 @@
   1.578      const M1 &_m1;
   1.579      const M2 &_m2;
   1.580    public:
   1.581 -    typedef MapBase<typename M1::Key, bool> Parent;
   1.582 -    typedef typename Parent::Key Key;
   1.583 -    typedef typename Parent::Value Value;
   1.584 +    ///\e
   1.585 +    typedef typename M1::Key Key;
   1.586 +    ///\e
   1.587 +    typedef bool Value;
   1.588  
   1.589      /// Constructor
   1.590      OrMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
   1.591 -    /// \e
   1.592 +    ///\e
   1.593      Value operator[](const Key &k) const { return _m1[k]||_m2[k]; }
   1.594    };
   1.595  
   1.596 @@ -1506,13 +1528,14 @@
   1.597    class NotMap : public MapBase<typename M::Key, bool> {
   1.598      const M &_m;
   1.599    public:
   1.600 -    typedef MapBase<typename M::Key, bool> Parent;
   1.601 -    typedef typename Parent::Key Key;
   1.602 -    typedef typename Parent::Value Value;
   1.603 +    ///\e
   1.604 +    typedef typename M::Key Key;
   1.605 +    ///\e
   1.606 +    typedef bool Value;
   1.607  
   1.608      /// Constructor
   1.609      NotMap(const M &m) : _m(m) {}
   1.610 -    /// \e
   1.611 +    ///\e
   1.612      Value operator[](const Key &k) const { return !_m[k]; }
   1.613    };
   1.614  
   1.615 @@ -1532,15 +1555,16 @@
   1.616    class NotWriteMap : public MapBase<typename M::Key, bool> {
   1.617      M &_m;
   1.618    public:
   1.619 -    typedef MapBase<typename M::Key, bool> Parent;
   1.620 -    typedef typename Parent::Key Key;
   1.621 -    typedef typename Parent::Value Value;
   1.622 +    ///\e
   1.623 +    typedef typename M::Key Key;
   1.624 +    ///\e
   1.625 +    typedef bool Value;
   1.626  
   1.627      /// Constructor
   1.628      NotWriteMap(M &m) : _m(m) {}
   1.629 -    /// \e
   1.630 +    ///\e
   1.631      Value operator[](const Key &k) const { return !_m[k]; }
   1.632 -    /// \e
   1.633 +    ///\e
   1.634      void set(const Key &k, bool v) { _m.set(k, !v); }
   1.635    };
   1.636  
   1.637 @@ -1595,13 +1619,14 @@
   1.638      const M1 &_m1;
   1.639      const M2 &_m2;
   1.640    public:
   1.641 -    typedef MapBase<typename M1::Key, bool> Parent;
   1.642 -    typedef typename Parent::Key Key;
   1.643 -    typedef typename Parent::Value Value;
   1.644 +    ///\e
   1.645 +    typedef typename M1::Key Key;
   1.646 +    ///\e
   1.647 +    typedef bool Value;
   1.648  
   1.649      /// Constructor
   1.650      EqualMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
   1.651 -    /// \e
   1.652 +    ///\e
   1.653      Value operator[](const Key &k) const { return _m1[k]==_m2[k]; }
   1.654    };
   1.655  
   1.656 @@ -1643,13 +1668,14 @@
   1.657      const M1 &_m1;
   1.658      const M2 &_m2;
   1.659    public:
   1.660 -    typedef MapBase<typename M1::Key, bool> Parent;
   1.661 -    typedef typename Parent::Key Key;
   1.662 -    typedef typename Parent::Value Value;
   1.663 +    ///\e
   1.664 +    typedef typename M1::Key Key;
   1.665 +    ///\e
   1.666 +    typedef bool Value;
   1.667  
   1.668      /// Constructor
   1.669      LessMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
   1.670 -    /// \e
   1.671 +    ///\e
   1.672      Value operator[](const Key &k) const { return _m1[k]<_m2[k]; }
   1.673    };
   1.674  
   1.675 @@ -1705,24 +1731,27 @@
   1.676    /// The simplest way of using this map is through the loggerBoolMap()
   1.677    /// function.
   1.678    ///
   1.679 -  /// \tparam It The type of the iterator.
   1.680 -  /// \tparam Ke The key type of the map. The default value set
   1.681 +  /// \tparam IT The type of the iterator.
   1.682 +  /// \tparam KEY The key type of the map. The default value set
   1.683    /// according to the iterator type should work in most cases.
   1.684    ///
   1.685    /// \note The container of the iterator must contain enough space
   1.686    /// for the elements or the iterator should be an inserter iterator.
   1.687  #ifdef DOXYGEN
   1.688 -  template <typename It, typename Ke>
   1.689 +  template <typename IT, typename KEY>
   1.690  #else
   1.691 -  template <typename It,
   1.692 -            typename Ke=typename _maps_bits::IteratorTraits<It>::Value>
   1.693 +  template <typename IT,
   1.694 +            typename KEY = typename _maps_bits::IteratorTraits<IT>::Value>
   1.695  #endif
   1.696 -  class LoggerBoolMap {
   1.697 +  class LoggerBoolMap : public MapBase<KEY, bool> {
   1.698    public:
   1.699 -    typedef It Iterator;
   1.700 -
   1.701 -    typedef Ke Key;
   1.702 +
   1.703 +    ///\e
   1.704 +    typedef KEY Key;
   1.705 +    ///\e
   1.706      typedef bool Value;
   1.707 +    ///\e
   1.708 +    typedef IT Iterator;
   1.709  
   1.710      /// Constructor
   1.711      LoggerBoolMap(Iterator it)
   1.712 @@ -1760,11 +1789,11 @@
   1.713    /// order of Dfs algorithm, as the following examples show.
   1.714    /// \code
   1.715    ///   std::vector<Node> v;
   1.716 -  ///   dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run();
   1.717 +  ///   dfs(g).processedMap(loggerBoolMap(std::back_inserter(v))).run(s);
   1.718    /// \endcode
   1.719    /// \code
   1.720    ///   std::vector<Node> v(countNodes(g));
   1.721 -  ///   dfs(g,s).processedMap(loggerBoolMap(v.begin())).run();
   1.722 +  ///   dfs(g).processedMap(loggerBoolMap(v.begin())).run(s);
   1.723    /// \endcode
   1.724    ///
   1.725    /// \note The container of the iterator must contain enough space
   1.726 @@ -1785,23 +1814,36 @@
   1.727    /// \addtogroup graph_maps
   1.728    /// @{
   1.729  
   1.730 -  /// Provides an immutable and unique id for each item in the graph.
   1.731 -
   1.732 -  /// The IdMap class provides a unique and immutable id for each item of the
   1.733 -  /// same type (e.g. node) in the graph. This id is <ul><li>\b unique:
   1.734 -  /// different items (nodes) get different ids <li>\b immutable: the id of an
   1.735 -  /// item (node) does not change (even if you delete other nodes).  </ul>
   1.736 -  /// Through this map you get access (i.e. can read) the inner id values of
   1.737 -  /// the items stored in the graph. This map can be inverted with its member
   1.738 -  /// class \c InverseMap or with the \c operator() member.
   1.739 +  /// \brief Provides an immutable and unique id for each item in a graph.
   1.740    ///
   1.741 -  template <typename _Graph, typename _Item>
   1.742 -  class IdMap {
   1.743 +  /// IdMap provides a unique and immutable id for each item of the
   1.744 +  /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is
   1.745 +  ///  - \b unique: different items get different ids,
   1.746 +  ///  - \b immutable: the id of an item does not change (even if you
   1.747 +  ///    delete other nodes).
   1.748 +  ///
   1.749 +  /// Using this map you get access (i.e. can read) the inner id values of
   1.750 +  /// the items stored in the graph, which is returned by the \c id()
   1.751 +  /// function of the graph. This map can be inverted with its member
   1.752 +  /// class \c InverseMap or with the \c operator()() member.
   1.753 +  ///
   1.754 +  /// \tparam GR The graph type.
   1.755 +  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
   1.756 +  /// \c GR::Edge).
   1.757 +  ///
   1.758 +  /// \see RangeIdMap
   1.759 +  template <typename GR, typename K>
   1.760 +  class IdMap : public MapBase<K, int> {
   1.761    public:
   1.762 -    typedef _Graph Graph;
   1.763 +    /// The graph type of IdMap.
   1.764 +    typedef GR Graph;
   1.765 +    typedef GR Digraph;
   1.766 +    /// The key type of IdMap (\c Node, \c Arc or \c Edge).
   1.767 +    typedef K Item;
   1.768 +    /// The key type of IdMap (\c Node, \c Arc or \c Edge).
   1.769 +    typedef K Key;
   1.770 +    /// The value type of IdMap.
   1.771      typedef int Value;
   1.772 -    typedef _Item Item;
   1.773 -    typedef _Item Key;
   1.774  
   1.775      /// \brief Constructor.
   1.776      ///
   1.777 @@ -1813,9 +1855,9 @@
   1.778      /// Gives back the immutable and unique \e id of the item.
   1.779      int operator[](const Item& item) const { return _graph->id(item);}
   1.780  
   1.781 -    /// \brief Gives back the item by its id.
   1.782 +    /// \brief Gives back the \e item by its id.
   1.783      ///
   1.784 -    /// Gives back the item by its id.
   1.785 +    /// Gives back the \e item by its id.
   1.786      Item operator()(int id) { return _graph->fromId(id, Item()); }
   1.787  
   1.788    private:
   1.789 @@ -1823,9 +1865,11 @@
   1.790  
   1.791    public:
   1.792  
   1.793 -    /// \brief The class represents the inverse of its owner (IdMap).
   1.794 +    /// \brief The inverse map type of IdMap.
   1.795      ///
   1.796 -    /// The class represents the inverse of its owner (IdMap).
   1.797 +    /// The inverse map type of IdMap. The subscript operator gives back
   1.798 +    /// an item by its id.
   1.799 +    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
   1.800      /// \see inverse()
   1.801      class InverseMap {
   1.802      public:
   1.803 @@ -1840,10 +1884,9 @@
   1.804        /// Constructor for creating an id-to-item map.
   1.805        explicit InverseMap(const IdMap& map) : _graph(map._graph) {}
   1.806  
   1.807 -      /// \brief Gives back the given item from its id.
   1.808 +      /// \brief Gives back an item by its id.
   1.809        ///
   1.810 -      /// Gives back the given item from its id.
   1.811 -      ///
   1.812 +      /// Gives back an item by its id.
   1.813        Item operator[](int id) const { return _graph->fromId(id, Item());}
   1.814  
   1.815      private:
   1.816 @@ -1854,165 +1897,220 @@
   1.817      ///
   1.818      /// Gives back the inverse of the IdMap.
   1.819      InverseMap inverse() const { return InverseMap(*_graph);}
   1.820 -
   1.821    };
   1.822  
   1.823 -
   1.824 -  /// \brief General invertable graph-map type.
   1.825 -
   1.826 -  /// This type provides simple invertable graph-maps.
   1.827 -  /// The InvertableMap wraps an arbitrary ReadWriteMap
   1.828 -  /// and if a key is set to a new value then store it
   1.829 -  /// in the inverse map.
   1.830 +  /// \brief Returns an \c IdMap class.
   1.831    ///
   1.832 -  /// The values of the map can be accessed
   1.833 -  /// with stl compatible forward iterator.
   1.834 +  /// This function just returns an \c IdMap class.
   1.835 +  /// \relates IdMap
   1.836 +  template <typename K, typename GR>
   1.837 +  inline IdMap<GR, K> idMap(const GR& graph) {
   1.838 +    return IdMap<GR, K>(graph);
   1.839 +  }
   1.840 +
   1.841 +  /// \brief General cross reference graph map type.
   1.842 +
   1.843 +  /// This class provides simple invertable graph maps.
   1.844 +  /// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap)
   1.845 +  /// and if a key is set to a new value, then stores it in the inverse map.
   1.846 +  /// The graph items can be accessed by their values either using
   1.847 +  /// \c InverseMap or \c operator()(), and the values of the map can be
   1.848 +  /// accessed with an STL compatible forward iterator (\c ValueIt).
   1.849 +  /// 
   1.850 +  /// This map is intended to be used when all associated values are
   1.851 +  /// different (the map is actually invertable) or there are only a few
   1.852 +  /// items with the same value.
   1.853 +  /// Otherwise consider to use \c IterableValueMap, which is more 
   1.854 +  /// suitable and more efficient for such cases. It provides iterators
   1.855 +  /// to traverse the items with the same associated value, however
   1.856 +  /// it does not have \c InverseMap.
   1.857    ///
   1.858 -  /// \tparam _Graph The graph type.
   1.859 -  /// \tparam _Item The item type of the graph.
   1.860 -  /// \tparam _Value The value type of the map.
   1.861 +  /// This type is not reference map, so it cannot be modified with
   1.862 +  /// the subscript operator.
   1.863 +  ///
   1.864 +  /// \tparam GR The graph type.
   1.865 +  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
   1.866 +  /// \c GR::Edge).
   1.867 +  /// \tparam V The value type of the map.
   1.868    ///
   1.869    /// \see IterableValueMap
   1.870 -  template <typename _Graph, typename _Item, typename _Value>
   1.871 -  class InvertableMap
   1.872 -    : protected ItemSetTraits<_Graph, _Item>::template Map<_Value>::Type {
   1.873 +  template <typename GR, typename K, typename V>
   1.874 +  class CrossRefMap
   1.875 +    : protected ItemSetTraits<GR, K>::template Map<V>::Type {
   1.876    private:
   1.877  
   1.878 -    typedef typename ItemSetTraits<_Graph, _Item>::
   1.879 -    template Map<_Value>::Type Map;
   1.880 -    typedef _Graph Graph;
   1.881 -
   1.882 -    typedef std::map<_Value, _Item> Container;
   1.883 +    typedef typename ItemSetTraits<GR, K>::
   1.884 +      template Map<V>::Type Map;
   1.885 +
   1.886 +    typedef std::multimap<V, K> Container;
   1.887      Container _inv_map;
   1.888  
   1.889    public:
   1.890  
   1.891 -    /// The key type of InvertableMap (Node, Arc, Edge).
   1.892 -    typedef typename Map::Key Key;
   1.893 -    /// The value type of the InvertableMap.
   1.894 -    typedef typename Map::Value Value;
   1.895 +    /// The graph type of CrossRefMap.
   1.896 +    typedef GR Graph;
   1.897 +    typedef GR Digraph;
   1.898 +    /// The key type of CrossRefMap (\c Node, \c Arc or \c Edge).
   1.899 +    typedef K Item;
   1.900 +    /// The key type of CrossRefMap (\c Node, \c Arc or \c Edge).
   1.901 +    typedef K Key;
   1.902 +    /// The value type of CrossRefMap.
   1.903 +    typedef V Value;
   1.904  
   1.905      /// \brief Constructor.
   1.906      ///
   1.907 -    /// Construct a new InvertableMap for the graph.
   1.908 -    ///
   1.909 -    explicit InvertableMap(const Graph& graph) : Map(graph) {}
   1.910 +    /// Construct a new CrossRefMap for the given graph.
   1.911 +    explicit CrossRefMap(const Graph& graph) : Map(graph) {}
   1.912  
   1.913      /// \brief Forward iterator for values.
   1.914      ///
   1.915 -    /// This iterator is an stl compatible forward
   1.916 +    /// This iterator is an STL compatible forward
   1.917      /// iterator on the values of the map. The values can
   1.918 -    /// be accessed in the [beginValue, endValue) range.
   1.919 -    ///
   1.920 -    class ValueIterator
   1.921 +    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
   1.922 +    /// They are considered with multiplicity, so each value is
   1.923 +    /// traversed for each item it is assigned to.
   1.924 +    class ValueIt
   1.925        : public std::iterator<std::forward_iterator_tag, Value> {
   1.926 -      friend class InvertableMap;
   1.927 +      friend class CrossRefMap;
   1.928      private:
   1.929 -      ValueIterator(typename Container::const_iterator _it)
   1.930 +      ValueIt(typename Container::const_iterator _it)
   1.931          : it(_it) {}
   1.932      public:
   1.933  
   1.934 -      ValueIterator() {}
   1.935 -
   1.936 -      ValueIterator& operator++() { ++it; return *this; }
   1.937 -      ValueIterator operator++(int) {
   1.938 -        ValueIterator tmp(*this);
   1.939 +      /// Constructor
   1.940 +      ValueIt() {}
   1.941 +
   1.942 +      /// \e
   1.943 +      ValueIt& operator++() { ++it; return *this; }
   1.944 +      /// \e
   1.945 +      ValueIt operator++(int) {
   1.946 +        ValueIt tmp(*this);
   1.947          operator++();
   1.948          return tmp;
   1.949        }
   1.950  
   1.951 +      /// \e
   1.952        const Value& operator*() const { return it->first; }
   1.953 +      /// \e
   1.954        const Value* operator->() const { return &(it->first); }
   1.955  
   1.956 -      bool operator==(ValueIterator jt) const { return it == jt.it; }
   1.957 -      bool operator!=(ValueIterator jt) const { return it != jt.it; }
   1.958 +      /// \e
   1.959 +      bool operator==(ValueIt jt) const { return it == jt.it; }
   1.960 +      /// \e
   1.961 +      bool operator!=(ValueIt jt) const { return it != jt.it; }
   1.962  
   1.963      private:
   1.964        typename Container::const_iterator it;
   1.965      };
   1.966 +    
   1.967 +    /// Alias for \c ValueIt
   1.968 +    typedef ValueIt ValueIterator;
   1.969  
   1.970      /// \brief Returns an iterator to the first value.
   1.971      ///
   1.972 -    /// Returns an stl compatible iterator to the
   1.973 +    /// Returns an STL compatible iterator to the
   1.974      /// first value of the map. The values of the
   1.975 -    /// map can be accessed in the [beginValue, endValue)
   1.976 +    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
   1.977      /// range.
   1.978 -    ValueIterator beginValue() const {
   1.979 -      return ValueIterator(_inv_map.begin());
   1.980 +    ValueIt beginValue() const {
   1.981 +      return ValueIt(_inv_map.begin());
   1.982      }
   1.983  
   1.984      /// \brief Returns an iterator after the last value.
   1.985      ///
   1.986 -    /// Returns an stl compatible iterator after the
   1.987 +    /// Returns an STL compatible iterator after the
   1.988      /// last value of the map. The values of the
   1.989 -    /// map can be accessed in the [beginValue, endValue)
   1.990 +    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
   1.991      /// range.
   1.992 -    ValueIterator endValue() const {
   1.993 -      return ValueIterator(_inv_map.end());
   1.994 +    ValueIt endValue() const {
   1.995 +      return ValueIt(_inv_map.end());
   1.996      }
   1.997  
   1.998 -    /// \brief The setter function of the map.
   1.999 +    /// \brief Sets the value associated with the given key.
  1.1000      ///
  1.1001 -    /// Sets the mapped value.
  1.1002 +    /// Sets the value associated with the given key.
  1.1003      void set(const Key& key, const Value& val) {
  1.1004        Value oldval = Map::operator[](key);
  1.1005 -      typename Container::iterator it = _inv_map.find(oldval);
  1.1006 -      if (it != _inv_map.end() && it->second == key) {
  1.1007 -        _inv_map.erase(it);
  1.1008 +      typename Container::iterator it;
  1.1009 +      for (it = _inv_map.equal_range(oldval).first;
  1.1010 +           it != _inv_map.equal_range(oldval).second; ++it) {
  1.1011 +        if (it->second == key) {
  1.1012 +          _inv_map.erase(it);
  1.1013 +          break;
  1.1014 +        }
  1.1015        }
  1.1016 -      _inv_map.insert(make_pair(val, key));
  1.1017 +      _inv_map.insert(std::make_pair(val, key));
  1.1018        Map::set(key, val);
  1.1019      }
  1.1020  
  1.1021 -    /// \brief The getter function of the map.
  1.1022 +    /// \brief Returns the value associated with the given key.
  1.1023      ///
  1.1024 -    /// It gives back the value associated with the key.
  1.1025 +    /// Returns the value associated with the given key.
  1.1026      typename MapTraits<Map>::ConstReturnValue
  1.1027      operator[](const Key& key) const {
  1.1028        return Map::operator[](key);
  1.1029      }
  1.1030  
  1.1031 -    /// \brief Gives back the item by its value.
  1.1032 +    /// \brief Gives back an item by its value.
  1.1033      ///
  1.1034 -    /// Gives back the item by its value.
  1.1035 -    Key operator()(const Value& key) const {
  1.1036 -      typename Container::const_iterator it = _inv_map.find(key);
  1.1037 +    /// This function gives back an item that is assigned to
  1.1038 +    /// the given value or \c INVALID if no such item exists.
  1.1039 +    /// If there are more items with the same associated value,
  1.1040 +    /// only one of them is returned.
  1.1041 +    Key operator()(const Value& val) const {
  1.1042 +      typename Container::const_iterator it = _inv_map.find(val);
  1.1043        return it != _inv_map.end() ? it->second : INVALID;
  1.1044      }
  1.1045 +    
  1.1046 +    /// \brief Returns the number of items with the given value.
  1.1047 +    ///
  1.1048 +    /// This function returns the number of items with the given value
  1.1049 +    /// associated with it.
  1.1050 +    int count(const Value &val) const {
  1.1051 +      return _inv_map.count(val);
  1.1052 +    }
  1.1053  
  1.1054    protected:
  1.1055  
  1.1056 -    /// \brief Erase the key from the map.
  1.1057 +    /// \brief Erase the key from the map and the inverse map.
  1.1058      ///
  1.1059 -    /// Erase the key to the map. It is called by the
  1.1060 +    /// Erase the key from the map and the inverse map. It is called by the
  1.1061      /// \c AlterationNotifier.
  1.1062      virtual void erase(const Key& key) {
  1.1063        Value val = Map::operator[](key);
  1.1064 -      typename Container::iterator it = _inv_map.find(val);
  1.1065 -      if (it != _inv_map.end() && it->second == key) {
  1.1066 -        _inv_map.erase(it);
  1.1067 +      typename Container::iterator it;
  1.1068 +      for (it = _inv_map.equal_range(val).first;
  1.1069 +           it != _inv_map.equal_range(val).second; ++it) {
  1.1070 +        if (it->second == key) {
  1.1071 +          _inv_map.erase(it);
  1.1072 +          break;
  1.1073 +        }
  1.1074        }
  1.1075        Map::erase(key);
  1.1076      }
  1.1077  
  1.1078 -    /// \brief Erase more keys from the map.
  1.1079 +    /// \brief Erase more keys from the map and the inverse map.
  1.1080      ///
  1.1081 -    /// Erase more keys from the map. It is called by the
  1.1082 +    /// Erase more keys from the map and the inverse map. It is called by the
  1.1083      /// \c AlterationNotifier.
  1.1084      virtual void erase(const std::vector<Key>& keys) {
  1.1085        for (int i = 0; i < int(keys.size()); ++i) {
  1.1086          Value val = Map::operator[](keys[i]);
  1.1087 -        typename Container::iterator it = _inv_map.find(val);
  1.1088 -        if (it != _inv_map.end() && it->second == keys[i]) {
  1.1089 -          _inv_map.erase(it);
  1.1090 +        typename Container::iterator it;
  1.1091 +        for (it = _inv_map.equal_range(val).first;
  1.1092 +             it != _inv_map.equal_range(val).second; ++it) {
  1.1093 +          if (it->second == keys[i]) {
  1.1094 +            _inv_map.erase(it);
  1.1095 +            break;
  1.1096 +          }
  1.1097          }
  1.1098        }
  1.1099        Map::erase(keys);
  1.1100      }
  1.1101  
  1.1102 -    /// \brief Clear the keys from the map and inverse map.
  1.1103 +    /// \brief Clear the keys from the map and the inverse map.
  1.1104      ///
  1.1105 -    /// Clear the keys from the map and inverse map. It is called by the
  1.1106 +    /// Clear the keys from the map and the inverse map. It is called by the
  1.1107      /// \c AlterationNotifier.
  1.1108      virtual void clear() {
  1.1109        _inv_map.clear();
  1.1110 @@ -2021,79 +2119,90 @@
  1.1111  
  1.1112    public:
  1.1113  
  1.1114 -    /// \brief The inverse map type.
  1.1115 +    /// \brief The inverse map type of CrossRefMap.
  1.1116      ///
  1.1117 -    /// The inverse of this map. The subscript operator of the map
  1.1118 -    /// gives back always the item what was last assigned to the value.
  1.1119 +    /// The inverse map type of CrossRefMap. The subscript operator gives
  1.1120 +    /// back an item by its value.
  1.1121 +    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
  1.1122 +    /// \see inverse()
  1.1123      class InverseMap {
  1.1124      public:
  1.1125 -      /// \brief Constructor of the InverseMap.
  1.1126 +      /// \brief Constructor
  1.1127        ///
  1.1128        /// Constructor of the InverseMap.
  1.1129 -      explicit InverseMap(const InvertableMap& inverted)
  1.1130 +      explicit InverseMap(const CrossRefMap& inverted)
  1.1131          : _inverted(inverted) {}
  1.1132  
  1.1133        /// The value type of the InverseMap.
  1.1134 -      typedef typename InvertableMap::Key Value;
  1.1135 +      typedef typename CrossRefMap::Key Value;
  1.1136        /// The key type of the InverseMap.
  1.1137 -      typedef typename InvertableMap::Value Key;
  1.1138 +      typedef typename CrossRefMap::Value Key;
  1.1139  
  1.1140        /// \brief Subscript operator.
  1.1141        ///
  1.1142 -      /// Subscript operator. It gives back always the item
  1.1143 -      /// what was last assigned to the value.
  1.1144 +      /// Subscript operator. It gives back an item
  1.1145 +      /// that is assigned to the given value or \c INVALID
  1.1146 +      /// if no such item exists.
  1.1147        Value operator[](const Key& key) const {
  1.1148          return _inverted(key);
  1.1149        }
  1.1150  
  1.1151      private:
  1.1152 -      const InvertableMap& _inverted;
  1.1153 +      const CrossRefMap& _inverted;
  1.1154      };
  1.1155  
  1.1156 -    /// \brief It gives back the just readable inverse map.
  1.1157 +    /// \brief Gives back the inverse of the map.
  1.1158      ///
  1.1159 -    /// It gives back the just readable inverse map.
  1.1160 +    /// Gives back the inverse of the CrossRefMap.
  1.1161      InverseMap inverse() const {
  1.1162        return InverseMap(*this);
  1.1163      }
  1.1164  
  1.1165    };
  1.1166  
  1.1167 -  /// \brief Provides a mutable, continuous and unique descriptor for each
  1.1168 -  /// item in the graph.
  1.1169 +  /// \brief Provides continuous and unique id for the
  1.1170 +  /// items of a graph.
  1.1171    ///
  1.1172 -  /// The DescriptorMap class provides a unique and continuous (but mutable)
  1.1173 -  /// descriptor (id) for each item of the same type (e.g. node) in the
  1.1174 -  /// graph. This id is <ul><li>\b unique: different items (nodes) get
  1.1175 -  /// different ids <li>\b continuous: the range of the ids is the set of
  1.1176 -  /// integers between 0 and \c n-1, where \c n is the number of the items of
  1.1177 -  /// this type (e.g. nodes) (so the id of a node can change if you delete an
  1.1178 -  /// other node, i.e. this id is mutable).  </ul> This map can be inverted
  1.1179 -  /// with its member class \c InverseMap, or with the \c operator() member.
  1.1180 +  /// RangeIdMap provides a unique and continuous
  1.1181 +  /// id for each item of a given type (\c Node, \c Arc or
  1.1182 +  /// \c Edge) in a graph. This id is
  1.1183 +  ///  - \b unique: different items get different ids,
  1.1184 +  ///  - \b continuous: the range of the ids is the set of integers
  1.1185 +  ///    between 0 and \c n-1, where \c n is the number of the items of
  1.1186 +  ///    this type (\c Node, \c Arc or \c Edge).
  1.1187 +  ///  - So, the ids can change when deleting an item of the same type.
  1.1188    ///
  1.1189 -  /// \tparam _Graph The graph class the \c DescriptorMap belongs to.
  1.1190 -  /// \tparam _Item The Item is the Key of the Map. It may be Node, Arc or
  1.1191 -  /// Edge.
  1.1192 -  template <typename _Graph, typename _Item>
  1.1193 -  class DescriptorMap
  1.1194 -    : protected ItemSetTraits<_Graph, _Item>::template Map<int>::Type {
  1.1195 -
  1.1196 -    typedef _Item Item;
  1.1197 -    typedef typename ItemSetTraits<_Graph, _Item>::template Map<int>::Type Map;
  1.1198 +  /// Thus this id is not (necessarily) the same as what can get using
  1.1199 +  /// the \c id() function of the graph or \ref IdMap.
  1.1200 +  /// This map can be inverted with its member class \c InverseMap,
  1.1201 +  /// or with the \c operator()() member.
  1.1202 +  ///
  1.1203 +  /// \tparam GR The graph type.
  1.1204 +  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
  1.1205 +  /// \c GR::Edge).
  1.1206 +  ///
  1.1207 +  /// \see IdMap
  1.1208 +  template <typename GR, typename K>
  1.1209 +  class RangeIdMap
  1.1210 +    : protected ItemSetTraits<GR, K>::template Map<int>::Type {
  1.1211 +
  1.1212 +    typedef typename ItemSetTraits<GR, K>::template Map<int>::Type Map;
  1.1213  
  1.1214    public:
  1.1215 -    /// The graph class of DescriptorMap.
  1.1216 -    typedef _Graph Graph;
  1.1217 -
  1.1218 -    /// The key type of DescriptorMap (Node, Arc, Edge).
  1.1219 -    typedef typename Map::Key Key;
  1.1220 -    /// The value type of DescriptorMap.
  1.1221 -    typedef typename Map::Value Value;
  1.1222 +    /// The graph type of RangeIdMap.
  1.1223 +    typedef GR Graph;
  1.1224 +    typedef GR Digraph;
  1.1225 +    /// The key type of RangeIdMap (\c Node, \c Arc or \c Edge).
  1.1226 +    typedef K Item;
  1.1227 +    /// The key type of RangeIdMap (\c Node, \c Arc or \c Edge).
  1.1228 +    typedef K Key;
  1.1229 +    /// The value type of RangeIdMap.
  1.1230 +    typedef int Value;
  1.1231  
  1.1232      /// \brief Constructor.
  1.1233      ///
  1.1234 -    /// Constructor for descriptor map.
  1.1235 -    explicit DescriptorMap(const Graph& _graph) : Map(_graph) {
  1.1236 +    /// Constructor.
  1.1237 +    explicit RangeIdMap(const Graph& gr) : Map(gr) {
  1.1238        Item it;
  1.1239        const typename Map::Notifier* nf = Map::notifier();
  1.1240        for (nf->first(it); it != INVALID; nf->next(it)) {
  1.1241 @@ -2104,7 +2213,7 @@
  1.1242  
  1.1243    protected:
  1.1244  
  1.1245 -    /// \brief Add a new key to the map.
  1.1246 +    /// \brief Adds a new key to the map.
  1.1247      ///
  1.1248      /// Add a new key to the map. It is called by the
  1.1249      /// \c AlterationNotifier.
  1.1250 @@ -2194,16 +2303,16 @@
  1.1251        _inv_map[pi] = q;
  1.1252      }
  1.1253  
  1.1254 -    /// \brief Gives back the \e descriptor of the item.
  1.1255 +    /// \brief Gives back the \e range \e id of the item
  1.1256      ///
  1.1257 -    /// Gives back the mutable and unique \e descriptor of the map.
  1.1258 +    /// Gives back the \e range \e id of the item.
  1.1259      int operator[](const Item& item) const {
  1.1260        return Map::operator[](item);
  1.1261      }
  1.1262  
  1.1263 -    /// \brief Gives back the item by its descriptor.
  1.1264 +    /// \brief Gives back the item belonging to a \e range \e id
  1.1265      ///
  1.1266 -    /// Gives back th item by its descriptor.
  1.1267 +    /// Gives back the item belonging to the given \e range \e id.
  1.1268      Item operator()(int id) const {
  1.1269        return _inv_map[id];
  1.1270      }
  1.1271 @@ -2214,27 +2323,30 @@
  1.1272      Container _inv_map;
  1.1273  
  1.1274    public:
  1.1275 -    /// \brief The inverse map type of DescriptorMap.
  1.1276 +
  1.1277 +    /// \brief The inverse map type of RangeIdMap.
  1.1278      ///
  1.1279 -    /// The inverse map type of DescriptorMap.
  1.1280 +    /// The inverse map type of RangeIdMap. The subscript operator gives
  1.1281 +    /// back an item by its \e range \e id.
  1.1282 +    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
  1.1283      class InverseMap {
  1.1284      public:
  1.1285 -      /// \brief Constructor of the InverseMap.
  1.1286 +      /// \brief Constructor
  1.1287        ///
  1.1288        /// Constructor of the InverseMap.
  1.1289 -      explicit InverseMap(const DescriptorMap& inverted)
  1.1290 +      explicit InverseMap(const RangeIdMap& inverted)
  1.1291          : _inverted(inverted) {}
  1.1292  
  1.1293  
  1.1294        /// The value type of the InverseMap.
  1.1295 -      typedef typename DescriptorMap::Key Value;
  1.1296 +      typedef typename RangeIdMap::Key Value;
  1.1297        /// The key type of the InverseMap.
  1.1298 -      typedef typename DescriptorMap::Value Key;
  1.1299 +      typedef typename RangeIdMap::Value Key;
  1.1300  
  1.1301        /// \brief Subscript operator.
  1.1302        ///
  1.1303        /// Subscript operator. It gives back the item
  1.1304 -      /// that the descriptor belongs to currently.
  1.1305 +      /// that the given \e range \e id currently belongs to.
  1.1306        Value operator[](const Key& key) const {
  1.1307          return _inverted(key);
  1.1308        }
  1.1309 @@ -2247,241 +2359,1134 @@
  1.1310        }
  1.1311  
  1.1312      private:
  1.1313 -      const DescriptorMap& _inverted;
  1.1314 +      const RangeIdMap& _inverted;
  1.1315      };
  1.1316  
  1.1317      /// \brief Gives back the inverse of the map.
  1.1318      ///
  1.1319 -    /// Gives back the inverse of the map.
  1.1320 +    /// Gives back the inverse of the RangeIdMap.
  1.1321      const InverseMap inverse() const {
  1.1322        return InverseMap(*this);
  1.1323      }
  1.1324    };
  1.1325  
  1.1326 -  /// \brief Returns the source of the given arc.
  1.1327 +  /// \brief Returns a \c RangeIdMap class.
  1.1328    ///
  1.1329 -  /// The SourceMap gives back the source Node of the given arc.
  1.1330 +  /// This function just returns an \c RangeIdMap class.
  1.1331 +  /// \relates RangeIdMap
  1.1332 +  template <typename K, typename GR>
  1.1333 +  inline RangeIdMap<GR, K> rangeIdMap(const GR& graph) {
  1.1334 +    return RangeIdMap<GR, K>(graph);
  1.1335 +  }
  1.1336 +  
  1.1337 +  /// \brief Dynamic iterable \c bool map.
  1.1338 +  ///
  1.1339 +  /// This class provides a special graph map type which can store a
  1.1340 +  /// \c bool value for graph items (\c Node, \c Arc or \c Edge).
  1.1341 +  /// For both \c true and \c false values it is possible to iterate on
  1.1342 +  /// the keys mapped to the value.
  1.1343 +  ///
  1.1344 +  /// This type is a reference map, so it can be modified with the
  1.1345 +  /// subscript operator.
  1.1346 +  ///
  1.1347 +  /// \tparam GR The graph type.
  1.1348 +  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
  1.1349 +  /// \c GR::Edge).
  1.1350 +  ///
  1.1351 +  /// \see IterableIntMap, IterableValueMap
  1.1352 +  /// \see CrossRefMap
  1.1353 +  template <typename GR, typename K>
  1.1354 +  class IterableBoolMap
  1.1355 +    : protected ItemSetTraits<GR, K>::template Map<int>::Type {
  1.1356 +  private:
  1.1357 +    typedef GR Graph;
  1.1358 +
  1.1359 +    typedef typename ItemSetTraits<GR, K>::ItemIt KeyIt;
  1.1360 +    typedef typename ItemSetTraits<GR, K>::template Map<int>::Type Parent;
  1.1361 +
  1.1362 +    std::vector<K> _array;
  1.1363 +    int _sep;
  1.1364 +
  1.1365 +  public:
  1.1366 +
  1.1367 +    /// Indicates that the map is reference map.
  1.1368 +    typedef True ReferenceMapTag;
  1.1369 +
  1.1370 +    /// The key type
  1.1371 +    typedef K Key;
  1.1372 +    /// The value type
  1.1373 +    typedef bool Value;
  1.1374 +    /// The const reference type.
  1.1375 +    typedef const Value& ConstReference;
  1.1376 +
  1.1377 +  private:
  1.1378 +
  1.1379 +    int position(const Key& key) const {
  1.1380 +      return Parent::operator[](key);
  1.1381 +    }
  1.1382 +
  1.1383 +  public:
  1.1384 +
  1.1385 +    /// \brief Reference to the value of the map.
  1.1386 +    ///
  1.1387 +    /// This class is similar to the \c bool type. It can be converted to
  1.1388 +    /// \c bool and it provides the same operators.
  1.1389 +    class Reference {
  1.1390 +      friend class IterableBoolMap;
  1.1391 +    private:
  1.1392 +      Reference(IterableBoolMap& map, const Key& key)
  1.1393 +        : _key(key), _map(map) {}
  1.1394 +    public:
  1.1395 +
  1.1396 +      Reference& operator=(const Reference& value) {
  1.1397 +        _map.set(_key, static_cast<bool>(value));
  1.1398 +         return *this;
  1.1399 +      }
  1.1400 +
  1.1401 +      operator bool() const {
  1.1402 +        return static_cast<const IterableBoolMap&>(_map)[_key];
  1.1403 +      }
  1.1404 +
  1.1405 +      Reference& operator=(bool value) {
  1.1406 +        _map.set(_key, value);
  1.1407 +        return *this;
  1.1408 +      }
  1.1409 +      Reference& operator&=(bool value) {
  1.1410 +        _map.set(_key, _map[_key] & value);
  1.1411 +        return *this;
  1.1412 +      }
  1.1413 +      Reference& operator|=(bool value) {
  1.1414 +        _map.set(_key, _map[_key] | value);
  1.1415 +        return *this;
  1.1416 +      }
  1.1417 +      Reference& operator^=(bool value) {
  1.1418 +        _map.set(_key, _map[_key] ^ value);
  1.1419 +        return *this;
  1.1420 +      }
  1.1421 +    private:
  1.1422 +      Key _key;
  1.1423 +      IterableBoolMap& _map;
  1.1424 +    };
  1.1425 +
  1.1426 +    /// \brief Constructor of the map with a default value.
  1.1427 +    ///
  1.1428 +    /// Constructor of the map with a default value.
  1.1429 +    explicit IterableBoolMap(const Graph& graph, bool def = false)
  1.1430 +      : Parent(graph) {
  1.1431 +      typename Parent::Notifier* nf = Parent::notifier();
  1.1432 +      Key it;
  1.1433 +      for (nf->first(it); it != INVALID; nf->next(it)) {
  1.1434 +        Parent::set(it, _array.size());
  1.1435 +        _array.push_back(it);
  1.1436 +      }
  1.1437 +      _sep = (def ? _array.size() : 0);
  1.1438 +    }
  1.1439 +
  1.1440 +    /// \brief Const subscript operator of the map.
  1.1441 +    ///
  1.1442 +    /// Const subscript operator of the map.
  1.1443 +    bool operator[](const Key& key) const {
  1.1444 +      return position(key) < _sep;
  1.1445 +    }
  1.1446 +
  1.1447 +    /// \brief Subscript operator of the map.
  1.1448 +    ///
  1.1449 +    /// Subscript operator of the map.
  1.1450 +    Reference operator[](const Key& key) {
  1.1451 +      return Reference(*this, key);
  1.1452 +    }
  1.1453 +
  1.1454 +    /// \brief Set operation of the map.
  1.1455 +    ///
  1.1456 +    /// Set operation of the map.
  1.1457 +    void set(const Key& key, bool value) {
  1.1458 +      int pos = position(key);
  1.1459 +      if (value) {
  1.1460 +        if (pos < _sep) return;
  1.1461 +        Key tmp = _array[_sep];
  1.1462 +        _array[_sep] = key;
  1.1463 +        Parent::set(key, _sep);
  1.1464 +        _array[pos] = tmp;
  1.1465 +        Parent::set(tmp, pos);
  1.1466 +        ++_sep;
  1.1467 +      } else {
  1.1468 +        if (pos >= _sep) return;
  1.1469 +        --_sep;
  1.1470 +        Key tmp = _array[_sep];
  1.1471 +        _array[_sep] = key;
  1.1472 +        Parent::set(key, _sep);
  1.1473 +        _array[pos] = tmp;
  1.1474 +        Parent::set(tmp, pos);
  1.1475 +      }
  1.1476 +    }
  1.1477 +
  1.1478 +    /// \brief Set all items.
  1.1479 +    ///
  1.1480 +    /// Set all items in the map.
  1.1481 +    /// \note Constant time operation.
  1.1482 +    void setAll(bool value) {
  1.1483 +      _sep = (value ? _array.size() : 0);
  1.1484 +    }
  1.1485 +
  1.1486 +    /// \brief Returns the number of the keys mapped to \c true.
  1.1487 +    ///
  1.1488 +    /// Returns the number of the keys mapped to \c true.
  1.1489 +    int trueNum() const {
  1.1490 +      return _sep;
  1.1491 +    }
  1.1492 +
  1.1493 +    /// \brief Returns the number of the keys mapped to \c false.
  1.1494 +    ///
  1.1495 +    /// Returns the number of the keys mapped to \c false.
  1.1496 +    int falseNum() const {
  1.1497 +      return _array.size() - _sep;
  1.1498 +    }
  1.1499 +
  1.1500 +    /// \brief Iterator for the keys mapped to \c true.
  1.1501 +    ///
  1.1502 +    /// Iterator for the keys mapped to \c true. It works
  1.1503 +    /// like a graph item iterator, it can be converted to
  1.1504 +    /// the key type of the map, incremented with \c ++ operator, and
  1.1505 +    /// if the iterator leaves the last valid key, it will be equal to
  1.1506 +    /// \c INVALID.
  1.1507 +    class TrueIt : public Key {
  1.1508 +    public:
  1.1509 +      typedef Key Parent;
  1.1510 +
  1.1511 +      /// \brief Creates an iterator.
  1.1512 +      ///
  1.1513 +      /// Creates an iterator. It iterates on the
  1.1514 +      /// keys mapped to \c true.
  1.1515 +      /// \param map The IterableBoolMap.
  1.1516 +      explicit TrueIt(const IterableBoolMap& map)
  1.1517 +        : Parent(map._sep > 0 ? map._array[map._sep - 1] : INVALID),
  1.1518 +          _map(&map) {}
  1.1519 +
  1.1520 +      /// \brief Invalid constructor \& conversion.
  1.1521 +      ///
  1.1522 +      /// This constructor initializes the iterator to be invalid.
  1.1523 +      /// \sa Invalid for more details.
  1.1524 +      TrueIt(Invalid) : Parent(INVALID), _map(0) {}
  1.1525 +
  1.1526 +      /// \brief Increment operator.
  1.1527 +      ///
  1.1528 +      /// Increment operator.
  1.1529 +      TrueIt& operator++() {
  1.1530 +        int pos = _map->position(*this);
  1.1531 +        Parent::operator=(pos > 0 ? _map->_array[pos - 1] : INVALID);
  1.1532 +        return *this;
  1.1533 +      }
  1.1534 +
  1.1535 +    private:
  1.1536 +      const IterableBoolMap* _map;
  1.1537 +    };
  1.1538 +
  1.1539 +    /// \brief Iterator for the keys mapped to \c false.
  1.1540 +    ///
  1.1541 +    /// Iterator for the keys mapped to \c false. It works
  1.1542 +    /// like a graph item iterator, it can be converted to
  1.1543 +    /// the key type of the map, incremented with \c ++ operator, and
  1.1544 +    /// if the iterator leaves the last valid key, it will be equal to
  1.1545 +    /// \c INVALID.
  1.1546 +    class FalseIt : public Key {
  1.1547 +    public:
  1.1548 +      typedef Key Parent;
  1.1549 +
  1.1550 +      /// \brief Creates an iterator.
  1.1551 +      ///
  1.1552 +      /// Creates an iterator. It iterates on the
  1.1553 +      /// keys mapped to \c false.
  1.1554 +      /// \param map The IterableBoolMap.
  1.1555 +      explicit FalseIt(const IterableBoolMap& map)
  1.1556 +        : Parent(map._sep < int(map._array.size()) ?
  1.1557 +                 map._array.back() : INVALID), _map(&map) {}
  1.1558 +
  1.1559 +      /// \brief Invalid constructor \& conversion.
  1.1560 +      ///
  1.1561 +      /// This constructor initializes the iterator to be invalid.
  1.1562 +      /// \sa Invalid for more details.
  1.1563 +      FalseIt(Invalid) : Parent(INVALID), _map(0) {}
  1.1564 +
  1.1565 +      /// \brief Increment operator.
  1.1566 +      ///
  1.1567 +      /// Increment operator.
  1.1568 +      FalseIt& operator++() {
  1.1569 +        int pos = _map->position(*this);
  1.1570 +        Parent::operator=(pos > _map->_sep ? _map->_array[pos - 1] : INVALID);
  1.1571 +        return *this;
  1.1572 +      }
  1.1573 +
  1.1574 +    private:
  1.1575 +      const IterableBoolMap* _map;
  1.1576 +    };
  1.1577 +
  1.1578 +    /// \brief Iterator for the keys mapped to a given value.
  1.1579 +    ///
  1.1580 +    /// Iterator for the keys mapped to a given value. It works
  1.1581 +    /// like a graph item iterator, it can be converted to
  1.1582 +    /// the key type of the map, incremented with \c ++ operator, and
  1.1583 +    /// if the iterator leaves the last valid key, it will be equal to
  1.1584 +    /// \c INVALID.
  1.1585 +    class ItemIt : public Key {
  1.1586 +    public:
  1.1587 +      typedef Key Parent;
  1.1588 +
  1.1589 +      /// \brief Creates an iterator with a value.
  1.1590 +      ///
  1.1591 +      /// Creates an iterator with a value. It iterates on the
  1.1592 +      /// keys mapped to the given value.
  1.1593 +      /// \param map The IterableBoolMap.
  1.1594 +      /// \param value The value.
  1.1595 +      ItemIt(const IterableBoolMap& map, bool value)
  1.1596 +        : Parent(value ? 
  1.1597 +                 (map._sep > 0 ?
  1.1598 +                  map._array[map._sep - 1] : INVALID) :
  1.1599 +                 (map._sep < int(map._array.size()) ?
  1.1600 +                  map._array.back() : INVALID)), _map(&map) {}
  1.1601 +
  1.1602 +      /// \brief Invalid constructor \& conversion.
  1.1603 +      ///
  1.1604 +      /// This constructor initializes the iterator to be invalid.
  1.1605 +      /// \sa Invalid for more details.
  1.1606 +      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
  1.1607 +
  1.1608 +      /// \brief Increment operator.
  1.1609 +      ///
  1.1610 +      /// Increment operator.
  1.1611 +      ItemIt& operator++() {
  1.1612 +        int pos = _map->position(*this);
  1.1613 +        int _sep = pos >= _map->_sep ? _map->_sep : 0;
  1.1614 +        Parent::operator=(pos > _sep ? _map->_array[pos - 1] : INVALID);
  1.1615 +        return *this;
  1.1616 +      }
  1.1617 +
  1.1618 +    private:
  1.1619 +      const IterableBoolMap* _map;
  1.1620 +    };
  1.1621 +
  1.1622 +  protected:
  1.1623 +
  1.1624 +    virtual void add(const Key& key) {
  1.1625 +      Parent::add(key);
  1.1626 +      Parent::set(key, _array.size());
  1.1627 +      _array.push_back(key);
  1.1628 +    }
  1.1629 +
  1.1630 +    virtual void add(const std::vector<Key>& keys) {
  1.1631 +      Parent::add(keys);
  1.1632 +      for (int i = 0; i < int(keys.size()); ++i) {
  1.1633 +        Parent::set(keys[i], _array.size());
  1.1634 +        _array.push_back(keys[i]);
  1.1635 +      }
  1.1636 +    }
  1.1637 +
  1.1638 +    virtual void erase(const Key& key) {
  1.1639 +      int pos = position(key);
  1.1640 +      if (pos < _sep) {
  1.1641 +        --_sep;
  1.1642 +        Parent::set(_array[_sep], pos);
  1.1643 +        _array[pos] = _array[_sep];
  1.1644 +        Parent::set(_array.back(), _sep);
  1.1645 +        _array[_sep] = _array.back();
  1.1646 +        _array.pop_back();
  1.1647 +      } else {
  1.1648 +        Parent::set(_array.back(), pos);
  1.1649 +        _array[pos] = _array.back();
  1.1650 +        _array.pop_back();
  1.1651 +      }
  1.1652 +      Parent::erase(key);
  1.1653 +    }
  1.1654 +
  1.1655 +    virtual void erase(const std::vector<Key>& keys) {
  1.1656 +      for (int i = 0; i < int(keys.size()); ++i) {
  1.1657 +        int pos = position(keys[i]);
  1.1658 +        if (pos < _sep) {
  1.1659 +          --_sep;
  1.1660 +          Parent::set(_array[_sep], pos);
  1.1661 +          _array[pos] = _array[_sep];
  1.1662 +          Parent::set(_array.back(), _sep);
  1.1663 +          _array[_sep] = _array.back();
  1.1664 +          _array.pop_back();
  1.1665 +        } else {
  1.1666 +          Parent::set(_array.back(), pos);
  1.1667 +          _array[pos] = _array.back();
  1.1668 +          _array.pop_back();
  1.1669 +        }
  1.1670 +      }
  1.1671 +      Parent::erase(keys);
  1.1672 +    }
  1.1673 +
  1.1674 +    virtual void build() {
  1.1675 +      Parent::build();
  1.1676 +      typename Parent::Notifier* nf = Parent::notifier();
  1.1677 +      Key it;
  1.1678 +      for (nf->first(it); it != INVALID; nf->next(it)) {
  1.1679 +        Parent::set(it, _array.size());
  1.1680 +        _array.push_back(it);
  1.1681 +      }
  1.1682 +      _sep = 0;
  1.1683 +    }
  1.1684 +
  1.1685 +    virtual void clear() {
  1.1686 +      _array.clear();
  1.1687 +      _sep = 0;
  1.1688 +      Parent::clear();
  1.1689 +    }
  1.1690 +
  1.1691 +  };
  1.1692 +
  1.1693 +
  1.1694 +  namespace _maps_bits {
  1.1695 +    template <typename Item>
  1.1696 +    struct IterableIntMapNode {
  1.1697 +      IterableIntMapNode() : value(-1) {}
  1.1698 +      IterableIntMapNode(int _value) : value(_value) {}
  1.1699 +      Item prev, next;
  1.1700 +      int value;
  1.1701 +    };
  1.1702 +  }
  1.1703 +
  1.1704 +  /// \brief Dynamic iterable integer map.
  1.1705 +  ///
  1.1706 +  /// This class provides a special graph map type which can store an
  1.1707 +  /// integer value for graph items (\c Node, \c Arc or \c Edge).
  1.1708 +  /// For each non-negative value it is possible to iterate on the keys
  1.1709 +  /// mapped to the value.
  1.1710 +  ///
  1.1711 +  /// This map is intended to be used with small integer values, for which
  1.1712 +  /// it is efficient, and supports iteration only for non-negative values.
  1.1713 +  /// If you need large values and/or iteration for negative integers,
  1.1714 +  /// consider to use \ref IterableValueMap instead.
  1.1715 +  ///
  1.1716 +  /// This type is a reference map, so it can be modified with the
  1.1717 +  /// subscript operator.
  1.1718 +  ///
  1.1719 +  /// \note The size of the data structure depends on the largest
  1.1720 +  /// value in the map.
  1.1721 +  ///
  1.1722 +  /// \tparam GR The graph type.
  1.1723 +  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
  1.1724 +  /// \c GR::Edge).
  1.1725 +  ///
  1.1726 +  /// \see IterableBoolMap, IterableValueMap
  1.1727 +  /// \see CrossRefMap
  1.1728 +  template <typename GR, typename K>
  1.1729 +  class IterableIntMap
  1.1730 +    : protected ItemSetTraits<GR, K>::
  1.1731 +        template Map<_maps_bits::IterableIntMapNode<K> >::Type {
  1.1732 +  public:
  1.1733 +    typedef typename ItemSetTraits<GR, K>::
  1.1734 +      template Map<_maps_bits::IterableIntMapNode<K> >::Type Parent;
  1.1735 +
  1.1736 +    /// The key type
  1.1737 +    typedef K Key;
  1.1738 +    /// The value type
  1.1739 +    typedef int Value;
  1.1740 +    /// The graph type
  1.1741 +    typedef GR Graph;
  1.1742 +
  1.1743 +    /// \brief Constructor of the map.
  1.1744 +    ///
  1.1745 +    /// Constructor of the map. It sets all values to -1.
  1.1746 +    explicit IterableIntMap(const Graph& graph)
  1.1747 +      : Parent(graph) {}
  1.1748 +
  1.1749 +    /// \brief Constructor of the map with a given value.
  1.1750 +    ///
  1.1751 +    /// Constructor of the map with a given value.
  1.1752 +    explicit IterableIntMap(const Graph& graph, int value)
  1.1753 +      : Parent(graph, _maps_bits::IterableIntMapNode<K>(value)) {
  1.1754 +      if (value >= 0) {
  1.1755 +        for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
  1.1756 +          lace(it);
  1.1757 +        }
  1.1758 +      }
  1.1759 +    }
  1.1760 +
  1.1761 +  private:
  1.1762 +
  1.1763 +    void unlace(const Key& key) {
  1.1764 +      typename Parent::Value& node = Parent::operator[](key);
  1.1765 +      if (node.value < 0) return;
  1.1766 +      if (node.prev != INVALID) {
  1.1767 +        Parent::operator[](node.prev).next = node.next;
  1.1768 +      } else {
  1.1769 +        _first[node.value] = node.next;
  1.1770 +      }
  1.1771 +      if (node.next != INVALID) {
  1.1772 +        Parent::operator[](node.next).prev = node.prev;
  1.1773 +      }
  1.1774 +      while (!_first.empty() && _first.back() == INVALID) {
  1.1775 +        _first.pop_back();
  1.1776 +      }
  1.1777 +    }
  1.1778 +
  1.1779 +    void lace(const Key& key) {
  1.1780 +      typename Parent::Value& node = Parent::operator[](key);
  1.1781 +      if (node.value < 0) return;
  1.1782 +      if (node.value >= int(_first.size())) {
  1.1783 +        _first.resize(node.value + 1, INVALID);
  1.1784 +      }
  1.1785 +      node.prev = INVALID;
  1.1786 +      node.next = _first[node.value];
  1.1787 +      if (node.next != INVALID) {
  1.1788 +        Parent::operator[](node.next).prev = key;
  1.1789 +      }
  1.1790 +      _first[node.value] = key;
  1.1791 +    }
  1.1792 +
  1.1793 +  public:
  1.1794 +
  1.1795 +    /// Indicates that the map is reference map.
  1.1796 +    typedef True ReferenceMapTag;
  1.1797 +
  1.1798 +    /// \brief Reference to the value of the map.
  1.1799 +    ///
  1.1800 +    /// This class is similar to the \c int type. It can
  1.1801 +    /// be converted to \c int and it has the same operators.
  1.1802 +    class Reference {
  1.1803 +      friend class IterableIntMap;
  1.1804 +    private:
  1.1805 +      Reference(IterableIntMap& map, const Key& key)
  1.1806 +        : _key(key), _map(map) {}
  1.1807 +    public:
  1.1808 +
  1.1809 +      Reference& operator=(const Reference& value) {
  1.1810 +        _map.set(_key, static_cast<const int&>(value));
  1.1811 +         return *this;
  1.1812 +      }
  1.1813 +
  1.1814 +      operator const int&() const {
  1.1815 +        return static_cast<const IterableIntMap&>(_map)[_key];
  1.1816 +      }
  1.1817 +
  1.1818 +      Reference& operator=(int value) {
  1.1819 +        _map.set(_key, value);
  1.1820 +        return *this;
  1.1821 +      }
  1.1822 +      Reference& operator++() {
  1.1823 +        _map.set(_key, _map[_key] + 1);
  1.1824 +        return *this;
  1.1825 +      }
  1.1826 +      int operator++(int) {
  1.1827 +        int value = _map[_key];
  1.1828 +        _map.set(_key, value + 1);
  1.1829 +        return value;
  1.1830 +      }
  1.1831 +      Reference& operator--() {
  1.1832 +        _map.set(_key, _map[_key] - 1);
  1.1833 +        return *this;
  1.1834 +      }
  1.1835 +      int operator--(int) {
  1.1836 +        int value = _map[_key];
  1.1837 +        _map.set(_key, value - 1);
  1.1838 +        return value;
  1.1839 +      }
  1.1840 +      Reference& operator+=(int value) {
  1.1841 +        _map.set(_key, _map[_key] + value);
  1.1842 +        return *this;
  1.1843 +      }
  1.1844 +      Reference& operator-=(int value) {
  1.1845 +        _map.set(_key, _map[_key] - value);
  1.1846 +        return *this;
  1.1847 +      }
  1.1848 +      Reference& operator*=(int value) {
  1.1849 +        _map.set(_key, _map[_key] * value);
  1.1850 +        return *this;
  1.1851 +      }
  1.1852 +      Reference& operator/=(int value) {
  1.1853 +        _map.set(_key, _map[_key] / value);
  1.1854 +        return *this;
  1.1855 +      }
  1.1856 +      Reference& operator%=(int value) {
  1.1857 +        _map.set(_key, _map[_key] % value);
  1.1858 +        return *this;
  1.1859 +      }
  1.1860 +      Reference& operator&=(int value) {
  1.1861 +        _map.set(_key, _map[_key] & value);
  1.1862 +        return *this;
  1.1863 +      }
  1.1864 +      Reference& operator|=(int value) {
  1.1865 +        _map.set(_key, _map[_key] | value);
  1.1866 +        return *this;
  1.1867 +      }
  1.1868 +      Reference& operator^=(int value) {
  1.1869 +        _map.set(_key, _map[_key] ^ value);
  1.1870 +        return *this;
  1.1871 +      }
  1.1872 +      Reference& operator<<=(int value) {
  1.1873 +        _map.set(_key, _map[_key] << value);
  1.1874 +        return *this;
  1.1875 +      }
  1.1876 +      Reference& operator>>=(int value) {
  1.1877 +        _map.set(_key, _map[_key] >> value);
  1.1878 +        return *this;
  1.1879 +      }
  1.1880 +
  1.1881 +    private:
  1.1882 +      Key _key;
  1.1883 +      IterableIntMap& _map;
  1.1884 +    };
  1.1885 +
  1.1886 +    /// The const reference type.
  1.1887 +    typedef const Value& ConstReference;
  1.1888 +
  1.1889 +    /// \brief Gives back the maximal value plus one.
  1.1890 +    ///
  1.1891 +    /// Gives back the maximal value plus one.
  1.1892 +    int size() const {
  1.1893 +      return _first.size();
  1.1894 +    }
  1.1895 +
  1.1896 +    /// \brief Set operation of the map.
  1.1897 +    ///
  1.1898 +    /// Set operation of the map.
  1.1899 +    void set(const Key& key, const Value& value) {
  1.1900 +      unlace(key);
  1.1901 +      Parent::operator[](key).value = value;
  1.1902 +      lace(key);
  1.1903 +    }
  1.1904 +
  1.1905 +    /// \brief Const subscript operator of the map.
  1.1906 +    ///
  1.1907 +    /// Const subscript operator of the map.
  1.1908 +    const Value& operator[](const Key& key) const {
  1.1909 +      return Parent::operator[](key).value;
  1.1910 +    }
  1.1911 +
  1.1912 +    /// \brief Subscript operator of the map.
  1.1913 +    ///
  1.1914 +    /// Subscript operator of the map.
  1.1915 +    Reference operator[](const Key& key) {
  1.1916 +      return Reference(*this, key);
  1.1917 +    }
  1.1918 +
  1.1919 +    /// \brief Iterator for the keys with the same value.
  1.1920 +    ///
  1.1921 +    /// Iterator for the keys with the same value. It works
  1.1922 +    /// like a graph item iterator, it can be converted to
  1.1923 +    /// the item type of the map, incremented with \c ++ operator, and
  1.1924 +    /// if the iterator leaves the last valid item, it will be equal to
  1.1925 +    /// \c INVALID.
  1.1926 +    class ItemIt : public Key {
  1.1927 +    public:
  1.1928 +      typedef Key Parent;
  1.1929 +
  1.1930 +      /// \brief Invalid constructor \& conversion.
  1.1931 +      ///
  1.1932 +      /// This constructor initializes the iterator to be invalid.
  1.1933 +      /// \sa Invalid for more details.
  1.1934 +      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
  1.1935 +
  1.1936 +      /// \brief Creates an iterator with a value.
  1.1937 +      ///
  1.1938 +      /// Creates an iterator with a value. It iterates on the
  1.1939 +      /// keys mapped to the given value.
  1.1940 +      /// \param map The IterableIntMap.
  1.1941 +      /// \param value The value.
  1.1942 +      ItemIt(const IterableIntMap& map, int value) : _map(&map) {
  1.1943 +        if (value < 0 || value >= int(_map->_first.size())) {
  1.1944 +          Parent::operator=(INVALID);
  1.1945 +        } else {
  1.1946 +          Parent::operator=(_map->_first[value]);
  1.1947 +        }
  1.1948 +      }
  1.1949 +
  1.1950 +      /// \brief Increment operator.
  1.1951 +      ///
  1.1952 +      /// Increment operator.
  1.1953 +      ItemIt& operator++() {
  1.1954 +        Parent::operator=(_map->IterableIntMap::Parent::
  1.1955 +                          operator[](static_cast<Parent&>(*this)).next);
  1.1956 +        return *this;
  1.1957 +      }
  1.1958 +
  1.1959 +    private:
  1.1960 +      const IterableIntMap* _map;
  1.1961 +    };
  1.1962 +
  1.1963 +  protected:
  1.1964 +
  1.1965 +    virtual void erase(const Key& key) {
  1.1966 +      unlace(key);
  1.1967 +      Parent::erase(key);
  1.1968 +    }
  1.1969 +
  1.1970 +    virtual void erase(const std::vector<Key>& keys) {
  1.1971 +      for (int i = 0; i < int(keys.size()); ++i) {
  1.1972 +        unlace(keys[i]);
  1.1973 +      }
  1.1974 +      Parent::erase(keys);
  1.1975 +    }
  1.1976 +
  1.1977 +    virtual void clear() {
  1.1978 +      _first.clear();
  1.1979 +      Parent::clear();
  1.1980 +    }
  1.1981 +
  1.1982 +  private:
  1.1983 +    std::vector<Key> _first;
  1.1984 +  };
  1.1985 +
  1.1986 +  namespace _maps_bits {
  1.1987 +    template <typename Item, typename Value>
  1.1988 +    struct IterableValueMapNode {
  1.1989 +      IterableValueMapNode(Value _value = Value()) : value(_value) {}
  1.1990 +      Item prev, next;
  1.1991 +      Value value;
  1.1992 +    };
  1.1993 +  }
  1.1994 +
  1.1995 +  /// \brief Dynamic iterable map for comparable values.
  1.1996 +  ///
  1.1997 +  /// This class provides a special graph map type which can store a
  1.1998 +  /// comparable value for graph items (\c Node, \c Arc or \c Edge).
  1.1999 +  /// For each value it is possible to iterate on the keys mapped to
  1.2000 +  /// the value (\c ItemIt), and the values of the map can be accessed
  1.2001 +  /// with an STL compatible forward iterator (\c ValueIt).
  1.2002 +  /// The map stores a linked list for each value, which contains
  1.2003 +  /// the items mapped to the value, and the used values are stored
  1.2004 +  /// in balanced binary tree (\c std::map).
  1.2005 +  ///
  1.2006 +  /// \ref IterableBoolMap and \ref IterableIntMap are similar classes
  1.2007 +  /// specialized for \c bool and \c int values, respectively.
  1.2008 +  ///
  1.2009 +  /// This type is not reference map, so it cannot be modified with
  1.2010 +  /// the subscript operator.
  1.2011 +  ///
  1.2012 +  /// \tparam GR The graph type.
  1.2013 +  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
  1.2014 +  /// \c GR::Edge).
  1.2015 +  /// \tparam V The value type of the map. It can be any comparable
  1.2016 +  /// value type.
  1.2017 +  ///
  1.2018 +  /// \see IterableBoolMap, IterableIntMap
  1.2019 +  /// \see CrossRefMap
  1.2020 +  template <typename GR, typename K, typename V>
  1.2021 +  class IterableValueMap
  1.2022 +    : protected ItemSetTraits<GR, K>::
  1.2023 +        template Map<_maps_bits::IterableValueMapNode<K, V> >::Type {
  1.2024 +  public:
  1.2025 +    typedef typename ItemSetTraits<GR, K>::
  1.2026 +      template Map<_maps_bits::IterableValueMapNode<K, V> >::Type Parent;
  1.2027 +
  1.2028 +    /// The key type
  1.2029 +    typedef K Key;
  1.2030 +    /// The value type
  1.2031 +    typedef V Value;
  1.2032 +    /// The graph type
  1.2033 +    typedef GR Graph;
  1.2034 +
  1.2035 +  public:
  1.2036 +
  1.2037 +    /// \brief Constructor of the map with a given value.
  1.2038 +    ///
  1.2039 +    /// Constructor of the map with a given value.
  1.2040 +    explicit IterableValueMap(const Graph& graph,
  1.2041 +                              const Value& value = Value())
  1.2042 +      : Parent(graph, _maps_bits::IterableValueMapNode<K, V>(value)) {
  1.2043 +      for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
  1.2044 +        lace(it);
  1.2045 +      }
  1.2046 +    }
  1.2047 +
  1.2048 +  protected:
  1.2049 +
  1.2050 +    void unlace(const Key& key) {
  1.2051 +      typename Parent::Value& node = Parent::operator[](key);
  1.2052 +      if (node.prev != INVALID) {
  1.2053 +        Parent::operator[](node.prev).next = node.next;
  1.2054 +      } else {
  1.2055 +        if (node.next != INVALID) {
  1.2056 +          _first[node.value] = node.next;
  1.2057 +        } else {
  1.2058 +          _first.erase(node.value);
  1.2059 +        }
  1.2060 +      }
  1.2061 +      if (node.next != INVALID) {
  1.2062 +        Parent::operator[](node.next).prev = node.prev;
  1.2063 +      }
  1.2064 +    }
  1.2065 +
  1.2066 +    void lace(const Key& key) {
  1.2067 +      typename Parent::Value& node = Parent::operator[](key);
  1.2068 +      typename std::map<Value, Key>::iterator it = _first.find(node.value);
  1.2069 +      if (it == _first.end()) {
  1.2070 +        node.prev = node.next = INVALID;
  1.2071 +        _first.insert(std::make_pair(node.value, key));
  1.2072 +      } else {
  1.2073 +        node.prev = INVALID;
  1.2074 +        node.next = it->second;
  1.2075 +        if (node.next != INVALID) {
  1.2076 +          Parent::operator[](node.next).prev = key;
  1.2077 +        }
  1.2078 +        it->second = key;
  1.2079 +      }
  1.2080 +    }
  1.2081 +
  1.2082 +  public:
  1.2083 +
  1.2084 +    /// \brief Forward iterator for values.
  1.2085 +    ///
  1.2086 +    /// This iterator is an STL compatible forward
  1.2087 +    /// iterator on the values of the map. The values can
  1.2088 +    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
  1.2089 +    class ValueIt
  1.2090 +      : public std::iterator<std::forward_iterator_tag, Value> {
  1.2091 +      friend class IterableValueMap;
  1.2092 +    private:
  1.2093 +      ValueIt(typename std::map<Value, Key>::const_iterator _it)
  1.2094 +        : it(_it) {}
  1.2095 +    public:
  1.2096 +
  1.2097 +      /// Constructor
  1.2098 +      ValueIt() {}
  1.2099 +
  1.2100 +      /// \e
  1.2101 +      ValueIt& operator++() { ++it; return *this; }
  1.2102 +      /// \e
  1.2103 +      ValueIt operator++(int) {
  1.2104 +        ValueIt tmp(*this);
  1.2105 +        operator++();
  1.2106 +        return tmp;
  1.2107 +      }
  1.2108 +
  1.2109 +      /// \e
  1.2110 +      const Value& operator*() const { return it->first; }
  1.2111 +      /// \e
  1.2112 +      const Value* operator->() const { return &(it->first); }
  1.2113 +
  1.2114 +      /// \e
  1.2115 +      bool operator==(ValueIt jt) const { return it == jt.it; }
  1.2116 +      /// \e
  1.2117 +      bool operator!=(ValueIt jt) const { return it != jt.it; }
  1.2118 +
  1.2119 +    private:
  1.2120 +      typename std::map<Value, Key>::const_iterator it;
  1.2121 +    };
  1.2122 +
  1.2123 +    /// \brief Returns an iterator to the first value.
  1.2124 +    ///
  1.2125 +    /// Returns an STL compatible iterator to the
  1.2126 +    /// first value of the map. The values of the
  1.2127 +    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
  1.2128 +    /// range.
  1.2129 +    ValueIt beginValue() const {
  1.2130 +      return ValueIt(_first.begin());
  1.2131 +    }
  1.2132 +
  1.2133 +    /// \brief Returns an iterator after the last value.
  1.2134 +    ///
  1.2135 +    /// Returns an STL compatible iterator after the
  1.2136 +    /// last value of the map. The values of the
  1.2137 +    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
  1.2138 +    /// range.
  1.2139 +    ValueIt endValue() const {
  1.2140 +      return ValueIt(_first.end());
  1.2141 +    }
  1.2142 +
  1.2143 +    /// \brief Set operation of the map.
  1.2144 +    ///
  1.2145 +    /// Set operation of the map.
  1.2146 +    void set(const Key& key, const Value& value) {
  1.2147 +      unlace(key);
  1.2148 +      Parent::operator[](key).value = value;
  1.2149 +      lace(key);
  1.2150 +    }
  1.2151 +
  1.2152 +    /// \brief Const subscript operator of the map.
  1.2153 +    ///
  1.2154 +    /// Const subscript operator of the map.
  1.2155 +    const Value& operator[](const Key& key) const {
  1.2156 +      return Parent::operator[](key).value;
  1.2157 +    }
  1.2158 +
  1.2159 +    /// \brief Iterator for the keys with the same value.
  1.2160 +    ///
  1.2161 +    /// Iterator for the keys with the same value. It works
  1.2162 +    /// like a graph item iterator, it can be converted to
  1.2163 +    /// the item type of the map, incremented with \c ++ operator, and
  1.2164 +    /// if the iterator leaves the last valid item, it will be equal to
  1.2165 +    /// \c INVALID.
  1.2166 +    class ItemIt : public Key {
  1.2167 +    public:
  1.2168 +      typedef Key Parent;
  1.2169 +
  1.2170 +      /// \brief Invalid constructor \& conversion.
  1.2171 +      ///
  1.2172 +      /// This constructor initializes the iterator to be invalid.
  1.2173 +      /// \sa Invalid for more details.
  1.2174 +      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
  1.2175 +
  1.2176 +      /// \brief Creates an iterator with a value.
  1.2177 +      ///
  1.2178 +      /// Creates an iterator with a value. It iterates on the
  1.2179 +      /// keys which have the given value.
  1.2180 +      /// \param map The IterableValueMap
  1.2181 +      /// \param value The value
  1.2182 +      ItemIt(const IterableValueMap& map, const Value& value) : _map(&map) {
  1.2183 +        typename std::map<Value, Key>::const_iterator it =
  1.2184 +          map._first.find(value);
  1.2185 +        if (it == map._first.end()) {
  1.2186 +          Parent::operator=(INVALID);
  1.2187 +        } else {
  1.2188 +          Parent::operator=(it->second);
  1.2189 +        }
  1.2190 +      }
  1.2191 +
  1.2192 +      /// \brief Increment operator.
  1.2193 +      ///
  1.2194 +      /// Increment Operator.
  1.2195 +      ItemIt& operator++() {
  1.2196 +        Parent::operator=(_map->IterableValueMap::Parent::
  1.2197 +                          operator[](static_cast<Parent&>(*this)).next);
  1.2198 +        return *this;
  1.2199 +      }
  1.2200 +
  1.2201 +
  1.2202 +    private:
  1.2203 +      const IterableValueMap* _map;
  1.2204 +    };
  1.2205 +
  1.2206 +  protected:
  1.2207 +
  1.2208 +    virtual void add(const Key& key) {
  1.2209 +      Parent::add(key);
  1.2210 +      unlace(key);
  1.2211 +    }
  1.2212 +
  1.2213 +    virtual void add(const std::vector<Key>& keys) {
  1.2214 +      Parent::add(keys);
  1.2215 +      for (int i = 0; i < int(keys.size()); ++i) {
  1.2216 +        lace(keys[i]);
  1.2217 +      }
  1.2218 +    }
  1.2219 +
  1.2220 +    virtual void erase(const Key& key) {
  1.2221 +      unlace(key);
  1.2222 +      Parent::erase(key);
  1.2223 +    }
  1.2224 +
  1.2225 +    virtual void erase(const std::vector<Key>& keys) {
  1.2226 +      for (int i = 0; i < int(keys.size()); ++i) {
  1.2227 +        unlace(keys[i]);
  1.2228 +      }
  1.2229 +      Parent::erase(keys);
  1.2230 +    }
  1.2231 +
  1.2232 +    virtual void build() {
  1.2233 +      Parent::build();
  1.2234 +      for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
  1.2235 +        lace(it);
  1.2236 +      }
  1.2237 +    }
  1.2238 +
  1.2239 +    virtual void clear() {
  1.2240 +      _first.clear();
  1.2241 +      Parent::clear();
  1.2242 +    }
  1.2243 +
  1.2244 +  private:
  1.2245 +    std::map<Value, Key> _first;
  1.2246 +  };
  1.2247 +
  1.2248 +  /// \brief Map of the source nodes of arcs in a digraph.
  1.2249 +  ///
  1.2250 +  /// SourceMap provides access for the source node of each arc in a digraph,
  1.2251 +  /// which is returned by the \c source() function of the digraph.
  1.2252 +  /// \tparam GR The digraph type.
  1.2253    /// \see TargetMap
  1.2254 -  template <typename Digraph>
  1.2255 +  template <typename GR>
  1.2256    class SourceMap {
  1.2257    public:
  1.2258  
  1.2259 -    typedef typename Digraph::Node Value;
  1.2260 -    typedef typename Digraph::Arc Key;
  1.2261 +    /// The key type (the \c Arc type of the digraph).
  1.2262 +    typedef typename GR::Arc Key;
  1.2263 +    /// The value type (the \c Node type of the digraph).
  1.2264 +    typedef typename GR::Node Value;
  1.2265  
  1.2266      /// \brief Constructor
  1.2267      ///
  1.2268 -    /// Constructor
  1.2269 +    /// Constructor.
  1.2270      /// \param digraph The digraph that the map belongs to.
  1.2271 -    explicit SourceMap(const Digraph& digraph) : _digraph(digraph) {}
  1.2272 -
  1.2273 -    /// \brief The subscript operator.
  1.2274 +    explicit SourceMap(const GR& digraph) : _graph(digraph) {}
  1.2275 +
  1.2276 +    /// \brief Returns the source node of the given arc.
  1.2277      ///
  1.2278 -    /// The subscript operator.
  1.2279 -    /// \param arc The arc
  1.2280 -    /// \return The source of the arc
  1.2281 +    /// Returns the source node of the given arc.
  1.2282      Value operator[](const Key& arc) const {
  1.2283 -      return _digraph.source(arc);
  1.2284 +      return _graph.source(arc);
  1.2285      }
  1.2286  
  1.2287    private:
  1.2288 -    const Digraph& _digraph;
  1.2289 +    const GR& _graph;
  1.2290    };
  1.2291  
  1.2292    /// \brief Returns a \c SourceMap class.
  1.2293    ///
  1.2294    /// This function just returns an \c SourceMap class.
  1.2295    /// \relates SourceMap
  1.2296 -  template <typename Digraph>
  1.2297 -  inline SourceMap<Digraph> sourceMap(const Digraph& digraph) {
  1.2298 -    return SourceMap<Digraph>(digraph);
  1.2299 +  template <typename GR>
  1.2300 +  inline SourceMap<GR> sourceMap(const GR& graph) {
  1.2301 +    return SourceMap<GR>(graph);
  1.2302    }
  1.2303  
  1.2304 -  /// \brief Returns the target of the given arc.
  1.2305 +  /// \brief Map of the target nodes of arcs in a digraph.
  1.2306    ///
  1.2307 -  /// The TargetMap gives back the target Node of the given arc.
  1.2308 +  /// TargetMap provides access for the target node of each arc in a digraph,
  1.2309 +  /// which is returned by the \c target() function of the digraph.
  1.2310 +  /// \tparam GR The digraph type.
  1.2311    /// \see SourceMap
  1.2312 -  template <typename Digraph>
  1.2313 +  template <typename GR>
  1.2314    class TargetMap {
  1.2315    public:
  1.2316  
  1.2317 -    typedef typename Digraph::Node Value;
  1.2318 -    typedef typename Digraph::Arc Key;
  1.2319 +    /// The key type (the \c Arc type of the digraph).
  1.2320 +    typedef typename GR::Arc Key;
  1.2321 +    /// The value type (the \c Node type of the digraph).
  1.2322 +    typedef typename GR::Node Value;
  1.2323  
  1.2324      /// \brief Constructor
  1.2325      ///
  1.2326 -    /// Constructor
  1.2327 +    /// Constructor.
  1.2328      /// \param digraph The digraph that the map belongs to.
  1.2329 -    explicit TargetMap(const Digraph& digraph) : _digraph(digraph) {}
  1.2330 -
  1.2331 -    /// \brief The subscript operator.
  1.2332 +    explicit TargetMap(const GR& digraph) : _graph(digraph) {}
  1.2333 +
  1.2334 +    /// \brief Returns the target node of the given arc.
  1.2335      ///
  1.2336 -    /// The subscript operator.
  1.2337 -    /// \param e The arc
  1.2338 -    /// \return The target of the arc
  1.2339 +    /// Returns the target node of the given arc.
  1.2340      Value operator[](const Key& e) const {
  1.2341 -      return _digraph.target(e);
  1.2342 +      return _graph.target(e);
  1.2343      }
  1.2344  
  1.2345    private:
  1.2346 -    const Digraph& _digraph;
  1.2347 +    const GR& _graph;
  1.2348    };
  1.2349  
  1.2350    /// \brief Returns a \c TargetMap class.
  1.2351    ///
  1.2352    /// This function just returns a \c TargetMap class.
  1.2353    /// \relates TargetMap
  1.2354 -  template <typename Digraph>
  1.2355 -  inline TargetMap<Digraph> targetMap(const Digraph& digraph) {
  1.2356 -    return TargetMap<Digraph>(digraph);
  1.2357 +  template <typename GR>
  1.2358 +  inline TargetMap<GR> targetMap(const GR& graph) {
  1.2359 +    return TargetMap<GR>(graph);
  1.2360    }
  1.2361  
  1.2362 -  /// \brief Returns the "forward" directed arc view of an edge.
  1.2363 +  /// \brief Map of the "forward" directed arc view of edges in a graph.
  1.2364    ///
  1.2365 -  /// Returns the "forward" directed arc view of an edge.
  1.2366 +  /// ForwardMap provides access for the "forward" directed arc view of
  1.2367 +  /// each edge in a graph, which is returned by the \c direct() function
  1.2368 +  /// of the graph with \c true parameter.
  1.2369 +  /// \tparam GR The graph type.
  1.2370    /// \see BackwardMap
  1.2371 -  template <typename Graph>
  1.2372 +  template <typename GR>
  1.2373    class ForwardMap {
  1.2374    public:
  1.2375  
  1.2376 -    typedef typename Graph::Arc Value;
  1.2377 -    typedef typename Graph::Edge Key;
  1.2378 +    /// The key type (the \c Edge type of the digraph).
  1.2379 +    typedef typename GR::Edge Key;
  1.2380 +    /// The value type (the \c Arc type of the digraph).
  1.2381 +    typedef typename GR::Arc Value;
  1.2382  
  1.2383      /// \brief Constructor
  1.2384      ///
  1.2385 -    /// Constructor
  1.2386 +    /// Constructor.
  1.2387      /// \param graph The graph that the map belongs to.
  1.2388 -    explicit ForwardMap(const Graph& graph) : _graph(graph) {}
  1.2389 -
  1.2390 -    /// \brief The subscript operator.
  1.2391 +    explicit ForwardMap(const GR& graph) : _graph(graph) {}
  1.2392 +
  1.2393 +    /// \brief Returns the "forward" directed arc view of the given edge.
  1.2394      ///
  1.2395 -    /// The subscript operator.
  1.2396 -    /// \param key An edge
  1.2397 -    /// \return The "forward" directed arc view of edge
  1.2398 +    /// Returns the "forward" directed arc view of the given edge.
  1.2399      Value operator[](const Key& key) const {
  1.2400        return _graph.direct(key, true);
  1.2401      }
  1.2402  
  1.2403    private:
  1.2404 -    const Graph& _graph;
  1.2405 +    const GR& _graph;
  1.2406    };
  1.2407  
  1.2408    /// \brief Returns a \c ForwardMap class.
  1.2409    ///
  1.2410    /// This function just returns an \c ForwardMap class.
  1.2411    /// \relates ForwardMap
  1.2412 -  template <typename Graph>
  1.2413 -  inline ForwardMap<Graph> forwardMap(const Graph& graph) {
  1.2414 -    return ForwardMap<Graph>(graph);
  1.2415 +  template <typename GR>
  1.2416 +  inline ForwardMap<GR> forwardMap(const GR& graph) {
  1.2417 +    return ForwardMap<GR>(graph);
  1.2418    }
  1.2419  
  1.2420 -  /// \brief Returns the "backward" directed arc view of an edge.
  1.2421 +  /// \brief Map of the "backward" directed arc view of edges in a graph.
  1.2422    ///
  1.2423 -  /// Returns the "backward" directed arc view of an edge.
  1.2424 +  /// BackwardMap provides access for the "backward" directed arc view of
  1.2425 +  /// each edge in a graph, which is returned by the \c direct() function
  1.2426 +  /// of the graph with \c false parameter.
  1.2427 +  /// \tparam GR The graph type.
  1.2428    /// \see ForwardMap
  1.2429 -  template <typename Graph>
  1.2430 +  template <typename GR>
  1.2431    class BackwardMap {
  1.2432    public:
  1.2433  
  1.2434 -    typedef typename Graph::Arc Value;
  1.2435 -    typedef typename Graph::Edge Key;
  1.2436 +    /// The key type (the \c Edge type of the digraph).
  1.2437 +    typedef typename GR::Edge Key;
  1.2438 +    /// The value type (the \c Arc type of the digraph).
  1.2439 +    typedef typename GR::Arc Value;
  1.2440  
  1.2441      /// \brief Constructor
  1.2442      ///
  1.2443 -    /// Constructor
  1.2444 +    /// Constructor.
  1.2445      /// \param graph The graph that the map belongs to.
  1.2446 -    explicit BackwardMap(const Graph& graph) : _graph(graph) {}
  1.2447 -
  1.2448 -    /// \brief The subscript operator.
  1.2449 +    explicit BackwardMap(const GR& graph) : _graph(graph) {}
  1.2450 +
  1.2451 +    /// \brief Returns the "backward" directed arc view of the given edge.
  1.2452      ///
  1.2453 -    /// The subscript operator.
  1.2454 -    /// \param key An edge
  1.2455 -    /// \return The "backward" directed arc view of edge
  1.2456 +    /// Returns the "backward" directed arc view of the given edge.
  1.2457      Value operator[](const Key& key) const {
  1.2458        return _graph.direct(key, false);
  1.2459      }
  1.2460  
  1.2461    private:
  1.2462 -    const Graph& _graph;
  1.2463 +    const GR& _graph;
  1.2464    };
  1.2465  
  1.2466    /// \brief Returns a \c BackwardMap class
  1.2467  
  1.2468    /// This function just returns a \c BackwardMap class.
  1.2469    /// \relates BackwardMap
  1.2470 -  template <typename Graph>
  1.2471 -  inline BackwardMap<Graph> backwardMap(const Graph& graph) {
  1.2472 -    return BackwardMap<Graph>(graph);
  1.2473 +  template <typename GR>
  1.2474 +  inline BackwardMap<GR> backwardMap(const GR& graph) {
  1.2475 +    return BackwardMap<GR>(graph);
  1.2476    }
  1.2477  
  1.2478 -  /// \brief Potential difference map
  1.2479 -  ///
  1.2480 -  /// If there is an potential map on the nodes then we
  1.2481 -  /// can get an arc map as we get the substraction of the
  1.2482 -  /// values of the target and source.
  1.2483 -  template <typename Digraph, typename NodeMap>
  1.2484 -  class PotentialDifferenceMap {
  1.2485 -  public:
  1.2486 -    typedef typename Digraph::Arc Key;
  1.2487 -    typedef typename NodeMap::Value Value;
  1.2488 -
  1.2489 -    /// \brief Constructor
  1.2490 -    ///
  1.2491 -    /// Contructor of the map
  1.2492 -    explicit PotentialDifferenceMap(const Digraph& digraph,
  1.2493 -                                    const NodeMap& potential)
  1.2494 -      : _digraph(digraph), _potential(potential) {}
  1.2495 -
  1.2496 -    /// \brief Const subscription operator
  1.2497 -    ///
  1.2498 -    /// Const subscription operator
  1.2499 -    Value operator[](const Key& arc) const {
  1.2500 -      return _potential[_digraph.target(arc)] -
  1.2501 -        _potential[_digraph.source(arc)];
  1.2502 -    }
  1.2503 -
  1.2504 -  private:
  1.2505 -    const Digraph& _digraph;
  1.2506 -    const NodeMap& _potential;
  1.2507 -  };
  1.2508 -
  1.2509 -  /// \brief Returns a PotentialDifferenceMap.
  1.2510 -  ///
  1.2511 -  /// This function just returns a PotentialDifferenceMap.
  1.2512 -  /// \relates PotentialDifferenceMap
  1.2513 -  template <typename Digraph, typename NodeMap>
  1.2514 -  PotentialDifferenceMap<Digraph, NodeMap>
  1.2515 -  potentialDifferenceMap(const Digraph& digraph, const NodeMap& potential) {
  1.2516 -    return PotentialDifferenceMap<Digraph, NodeMap>(digraph, potential);
  1.2517 -  }
  1.2518 -
  1.2519 -  /// \brief Map of the node in-degrees.
  1.2520 +  /// \brief Map of the in-degrees of nodes in a digraph.
  1.2521    ///
  1.2522    /// This map returns the in-degree of a node. Once it is constructed,
  1.2523 -  /// the degrees are stored in a standard NodeMap, so each query is done
  1.2524 +  /// the degrees are stored in a standard \c NodeMap, so each query is done
  1.2525    /// in constant time. On the other hand, the values are updated automatically
  1.2526    /// whenever the digraph changes.
  1.2527    ///
  1.2528 -  /// \warning Besides addNode() and addArc(), a digraph structure may provide
  1.2529 -  /// alternative ways to modify the digraph. The correct behavior of InDegMap
  1.2530 -  /// is not guarantied if these additional features are used. For example
  1.2531 -  /// the functions \ref ListDigraph::changeSource() "changeSource()",
  1.2532 +  /// \warning Besides \c addNode() and \c addArc(), a digraph structure
  1.2533 +  /// may provide alternative ways to modify the digraph.
  1.2534 +  /// The correct behavior of InDegMap is not guarantied if these additional
  1.2535 +  /// features are used. For example the functions
  1.2536 +  /// \ref ListDigraph::changeSource() "changeSource()",
  1.2537    /// \ref ListDigraph::changeTarget() "changeTarget()" and
  1.2538    /// \ref ListDigraph::reverseArc() "reverseArc()"
  1.2539    /// of \ref ListDigraph will \e not update the degree values correctly.
  1.2540    ///
  1.2541    /// \sa OutDegMap
  1.2542 -
  1.2543 -  template <typename _Digraph>
  1.2544 +  template <typename GR>
  1.2545    class InDegMap
  1.2546 -    : protected ItemSetTraits<_Digraph, typename _Digraph::Arc>
  1.2547 +    : protected ItemSetTraits<GR, typename GR::Arc>
  1.2548        ::ItemNotifier::ObserverBase {
  1.2549  
  1.2550    public:
  1.2551  
  1.2552 -    typedef _Digraph Digraph;
  1.2553 +    /// The graph type of InDegMap
  1.2554 +    typedef GR Graph;
  1.2555 +    typedef GR Digraph;
  1.2556 +    /// The key type
  1.2557 +    typedef typename Digraph::Node Key;
  1.2558 +    /// The value type
  1.2559      typedef int Value;
  1.2560 -    typedef typename Digraph::Node Key;
  1.2561  
  1.2562      typedef typename ItemSetTraits<Digraph, typename Digraph::Arc>
  1.2563      ::ItemNotifier::ObserverBase Parent;
  1.2564 @@ -2523,9 +3528,9 @@
  1.2565  
  1.2566      /// \brief Constructor.
  1.2567      ///
  1.2568 -    /// Constructor for creating in-degree map.
  1.2569 -    explicit InDegMap(const Digraph& digraph)
  1.2570 -      : _digraph(digraph), _deg(digraph) {
  1.2571 +    /// Constructor for creating an in-degree map.
  1.2572 +    explicit InDegMap(const Digraph& graph)
  1.2573 +      : _digraph(graph), _deg(graph) {
  1.2574        Parent::attach(_digraph.notifier(typename Digraph::Arc()));
  1.2575  
  1.2576        for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
  1.2577 @@ -2533,6 +3538,8 @@
  1.2578        }
  1.2579      }
  1.2580  
  1.2581 +    /// \brief Gives back the in-degree of a Node.
  1.2582 +    ///
  1.2583      /// Gives back the in-degree of a Node.
  1.2584      int operator[](const Key& key) const {
  1.2585        return _deg[key];
  1.2586 @@ -2579,33 +3586,37 @@
  1.2587      AutoNodeMap _deg;
  1.2588    };
  1.2589  
  1.2590 -  /// \brief Map of the node out-degrees.
  1.2591 +  /// \brief Map of the out-degrees of nodes in a digraph.
  1.2592    ///
  1.2593    /// This map returns the out-degree of a node. Once it is constructed,
  1.2594 -  /// the degrees are stored in a standard NodeMap, so each query is done
  1.2595 +  /// the degrees are stored in a standard \c NodeMap, so each query is done
  1.2596    /// in constant time. On the other hand, the values are updated automatically
  1.2597    /// whenever the digraph changes.
  1.2598    ///
  1.2599 -  /// \warning Besides addNode() and addArc(), a digraph structure may provide
  1.2600 -  /// alternative ways to modify the digraph. The correct behavior of OutDegMap
  1.2601 -  /// is not guarantied if these additional features are used. For example
  1.2602 -  /// the functions \ref ListDigraph::changeSource() "changeSource()",
  1.2603 +  /// \warning Besides \c addNode() and \c addArc(), a digraph structure
  1.2604 +  /// may provide alternative ways to modify the digraph.
  1.2605 +  /// The correct behavior of OutDegMap is not guarantied if these additional
  1.2606 +  /// features are used. For example the functions
  1.2607 +  /// \ref ListDigraph::changeSource() "changeSource()",
  1.2608    /// \ref ListDigraph::changeTarget() "changeTarget()" and
  1.2609    /// \ref ListDigraph::reverseArc() "reverseArc()"
  1.2610    /// of \ref ListDigraph will \e not update the degree values correctly.
  1.2611    ///
  1.2612    /// \sa InDegMap
  1.2613 -
  1.2614 -  template <typename _Digraph>
  1.2615 +  template <typename GR>
  1.2616    class OutDegMap
  1.2617 -    : protected ItemSetTraits<_Digraph, typename _Digraph::Arc>
  1.2618 +    : protected ItemSetTraits<GR, typename GR::Arc>
  1.2619        ::ItemNotifier::ObserverBase {
  1.2620  
  1.2621    public:
  1.2622  
  1.2623 -    typedef _Digraph Digraph;
  1.2624 +    /// The graph type of OutDegMap
  1.2625 +    typedef GR Graph;
  1.2626 +    typedef GR Digraph;
  1.2627 +    /// The key type
  1.2628 +    typedef typename Digraph::Node Key;
  1.2629 +    /// The value type
  1.2630      typedef int Value;
  1.2631 -    typedef typename Digraph::Node Key;
  1.2632  
  1.2633      typedef typename ItemSetTraits<Digraph, typename Digraph::Arc>
  1.2634      ::ItemNotifier::ObserverBase Parent;
  1.2635 @@ -2645,9 +3656,9 @@
  1.2636  
  1.2637      /// \brief Constructor.
  1.2638      ///
  1.2639 -    /// Constructor for creating out-degree map.
  1.2640 -    explicit OutDegMap(const Digraph& digraph)
  1.2641 -      : _digraph(digraph), _deg(digraph) {
  1.2642 +    /// Constructor for creating an out-degree map.
  1.2643 +    explicit OutDegMap(const Digraph& graph)
  1.2644 +      : _digraph(graph), _deg(graph) {
  1.2645        Parent::attach(_digraph.notifier(typename Digraph::Arc()));
  1.2646  
  1.2647        for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
  1.2648 @@ -2655,6 +3666,8 @@
  1.2649        }
  1.2650      }
  1.2651  
  1.2652 +    /// \brief Gives back the out-degree of a Node.
  1.2653 +    ///
  1.2654      /// Gives back the out-degree of a Node.
  1.2655      int operator[](const Key& key) const {
  1.2656        return _deg[key];
  1.2657 @@ -2701,6 +3714,56 @@
  1.2658      AutoNodeMap _deg;
  1.2659    };
  1.2660  
  1.2661 +  /// \brief Potential difference map
  1.2662 +  ///
  1.2663 +  /// PotentialDifferenceMap returns the difference between the potentials of
  1.2664 +  /// the source and target nodes of each arc in a digraph, i.e. it returns
  1.2665 +  /// \code
  1.2666 +  ///   potential[gr.target(arc)] - potential[gr.source(arc)].
  1.2667 +  /// \endcode
  1.2668 +  /// \tparam GR The digraph type.
  1.2669 +  /// \tparam POT A node map storing the potentials.
  1.2670 +  template <typename GR, typename POT>
  1.2671 +  class PotentialDifferenceMap {
  1.2672 +  public:
  1.2673 +    /// Key type
  1.2674 +    typedef typename GR::Arc Key;
  1.2675 +    /// Value type
  1.2676 +    typedef typename POT::Value Value;
  1.2677 +
  1.2678 +    /// \brief Constructor
  1.2679 +    ///
  1.2680 +    /// Contructor of the map.
  1.2681 +    explicit PotentialDifferenceMap(const GR& gr,
  1.2682 +                                    const POT& potential)
  1.2683 +      : _digraph(gr), _potential(potential) {}
  1.2684 +
  1.2685 +    /// \brief Returns the potential difference for the given arc.
  1.2686 +    ///
  1.2687 +    /// Returns the potential difference for the given arc, i.e.
  1.2688 +    /// \code
  1.2689 +    ///   potential[gr.target(arc)] - potential[gr.source(arc)].
  1.2690 +    /// \endcode
  1.2691 +    Value operator[](const Key& arc) const {
  1.2692 +      return _potential[_digraph.target(arc)] -
  1.2693 +        _potential[_digraph.source(arc)];
  1.2694 +    }
  1.2695 +
  1.2696 +  private:
  1.2697 +    const GR& _digraph;
  1.2698 +    const POT& _potential;
  1.2699 +  };
  1.2700 +
  1.2701 +  /// \brief Returns a PotentialDifferenceMap.
  1.2702 +  ///
  1.2703 +  /// This function just returns a PotentialDifferenceMap.
  1.2704 +  /// \relates PotentialDifferenceMap
  1.2705 +  template <typename GR, typename POT>
  1.2706 +  PotentialDifferenceMap<GR, POT>
  1.2707 +  potentialDifferenceMap(const GR& gr, const POT& potential) {
  1.2708 +    return PotentialDifferenceMap<GR, POT>(gr, potential);
  1.2709 +  }
  1.2710 +
  1.2711    /// @}
  1.2712  }
  1.2713