1.1 --- a/lemon/maps.h Thu Dec 10 17:05:35 2009 +0100
1.2 +++ b/lemon/maps.h Thu Dec 10 17:18:25 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,7 +56,7 @@
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 @@ -90,7 +89,7 @@
1.30 /// value to each key.
1.31 ///
1.32 /// In other aspects it is equivalent to \c NullMap.
1.33 - /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
1.34 + /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap"
1.35 /// concept, but it absorbs the data written to it.
1.36 ///
1.37 /// The simplest way of using this map is through the constMap()
1.38 @@ -159,7 +158,7 @@
1.39 /// value to each key.
1.40 ///
1.41 /// In other aspects it is equivalent to \c NullMap.
1.42 - /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap"
1.43 + /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap"
1.44 /// concept, but it absorbs the data written to it.
1.45 ///
1.46 /// The simplest way of using this map is through the constMap()
1.47 @@ -231,10 +230,10 @@
1.48 ///
1.49 /// This map is essentially a wrapper for \c std::vector. It assigns
1.50 /// values to integer keys from the range <tt>[0..size-1]</tt>.
1.51 - /// It can be used with some data structures, for example
1.52 - /// \c UnionFind, \c BinHeap, when the used items are small
1.53 - /// integers. This map conforms the \ref concepts::ReferenceMap
1.54 - /// "ReferenceMap" concept.
1.55 + /// It can be used together with some data structures, e.g.
1.56 + /// heap types and \c UnionFind, when the used items are small
1.57 + /// integers. This map conforms to the \ref concepts::ReferenceMap
1.58 + /// "ReferenceMap" concept.
1.59 ///
1.60 /// The simplest way of using this map is through the rangeMap()
1.61 /// function.
1.62 @@ -341,7 +340,7 @@
1.63 /// that you can specify a default value for the keys that are not
1.64 /// stored actually. This value can be different from the default
1.65 /// contructed value (i.e. \c %Value()).
1.66 - /// This type conforms the \ref concepts::ReferenceMap "ReferenceMap"
1.67 + /// This type conforms to the \ref concepts::ReferenceMap "ReferenceMap"
1.68 /// concept.
1.69 ///
1.70 /// This map is useful if a default value should be assigned to most of
1.71 @@ -349,9 +348,9 @@
1.72 /// keys (i.e. the map is "sparse").
1.73 /// The name of this type also refers to this important usage.
1.74 ///
1.75 - /// Apart form that this map can be used in many other cases since it
1.76 + /// Apart form that, this map can be used in many other cases since it
1.77 /// is based on \c std::map, which is a general associative container.
1.78 - /// However keep in mind that it is usually not as efficient as other
1.79 + /// However, keep in mind that it is usually not as efficient as other
1.80 /// maps.
1.81 ///
1.82 /// The simplest way of using this map is through the sparseMap()
1.83 @@ -707,7 +706,7 @@
1.84 /// "readable map" to another type using the default conversion.
1.85 /// The \c Key type of it is inherited from \c M and the \c Value
1.86 /// type is \c V.
1.87 - /// This type conforms the \ref concepts::ReadMap "ReadMap" concept.
1.88 + /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
1.89 ///
1.90 /// The simplest way of using this map is through the convertMap()
1.91 /// function.
1.92 @@ -1786,22 +1785,22 @@
1.93 ///
1.94 /// The most important usage of it is storing certain nodes or arcs
1.95 /// that were marked \c true by an algorithm.
1.96 - /// For example it makes easier to store the nodes in the processing
1.97 + /// For example, it makes easier to store the nodes in the processing
1.98 /// order of Dfs algorithm, as the following examples show.
1.99 /// \code
1.100 /// std::vector<Node> v;
1.101 - /// dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run();
1.102 + /// dfs(g).processedMap(loggerBoolMap(std::back_inserter(v))).run(s);
1.103 /// \endcode
1.104 /// \code
1.105 /// std::vector<Node> v(countNodes(g));
1.106 - /// dfs(g,s).processedMap(loggerBoolMap(v.begin())).run();
1.107 + /// dfs(g).processedMap(loggerBoolMap(v.begin())).run(s);
1.108 /// \endcode
1.109 ///
1.110 /// \note The container of the iterator must contain enough space
1.111 /// for the elements or the iterator should be an inserter iterator.
1.112 ///
1.113 /// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so
1.114 - /// it cannot be used when a readable map is needed, for example as
1.115 + /// it cannot be used when a readable map is needed, for example, as
1.116 /// \c ReachedMap for \c Bfs, \c Dfs and \c Dijkstra algorithms.
1.117 ///
1.118 /// \relates LoggerBoolMap
1.119 @@ -1818,7 +1817,7 @@
1.120 /// \brief Provides an immutable and unique id for each item in a graph.
1.121 ///
1.122 /// IdMap provides a unique and immutable id for each item of the
1.123 - /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is
1.124 + /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is
1.125 /// - \b unique: different items get different ids,
1.126 /// - \b immutable: the id of an item does not change (even if you
1.127 /// delete other nodes).
1.128 @@ -1826,7 +1825,7 @@
1.129 /// Using this map you get access (i.e. can read) the inner id values of
1.130 /// the items stored in the graph, which is returned by the \c id()
1.131 /// function of the graph. This map can be inverted with its member
1.132 - /// class \c InverseMap or with the \c operator() member.
1.133 + /// class \c InverseMap or with the \c operator()() member.
1.134 ///
1.135 /// \tparam GR The graph type.
1.136 /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1.137 @@ -1866,9 +1865,11 @@
1.138
1.139 public:
1.140
1.141 - /// \brief This class represents the inverse of its owner (IdMap).
1.142 + /// \brief The inverse map type of IdMap.
1.143 ///
1.144 - /// This class represents the inverse of its owner (IdMap).
1.145 + /// The inverse map type of IdMap. The subscript operator gives back
1.146 + /// an item by its id.
1.147 + /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
1.148 /// \see inverse()
1.149 class InverseMap {
1.150 public:
1.151 @@ -1883,9 +1884,9 @@
1.152 /// Constructor for creating an id-to-item map.
1.153 explicit InverseMap(const IdMap& map) : _graph(map._graph) {}
1.154
1.155 - /// \brief Gives back the given item from its id.
1.156 + /// \brief Gives back an item by its id.
1.157 ///
1.158 - /// Gives back the given item from its id.
1.159 + /// Gives back an item by its id.
1.160 Item operator[](int id) const { return _graph->fromId(id, Item());}
1.161
1.162 private:
1.163 @@ -1898,16 +1899,34 @@
1.164 InverseMap inverse() const { return InverseMap(*_graph);}
1.165 };
1.166
1.167 + /// \brief Returns an \c IdMap class.
1.168 + ///
1.169 + /// This function just returns an \c IdMap class.
1.170 + /// \relates IdMap
1.171 + template <typename K, typename GR>
1.172 + inline IdMap<GR, K> idMap(const GR& graph) {
1.173 + return IdMap<GR, K>(graph);
1.174 + }
1.175
1.176 /// \brief General cross reference graph map type.
1.177
1.178 /// This class provides simple invertable graph maps.
1.179 - /// It wraps an arbitrary \ref concepts::ReadWriteMap "ReadWriteMap"
1.180 - /// and if a key is set to a new value then store it
1.181 - /// in the inverse map.
1.182 + /// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap)
1.183 + /// and if a key is set to a new value, then stores it in the inverse map.
1.184 + /// The graph items can be accessed by their values either using
1.185 + /// \c InverseMap or \c operator()(), and the values of the map can be
1.186 + /// accessed with an STL compatible forward iterator (\c ValueIt).
1.187 + ///
1.188 + /// This map is intended to be used when all associated values are
1.189 + /// different (the map is actually invertable) or there are only a few
1.190 + /// items with the same value.
1.191 + /// Otherwise consider to use \c IterableValueMap, which is more
1.192 + /// suitable and more efficient for such cases. It provides iterators
1.193 + /// to traverse the items with the same associated value, but
1.194 + /// it does not have \c InverseMap.
1.195 ///
1.196 - /// The values of the map can be accessed
1.197 - /// with stl compatible forward iterator.
1.198 + /// This type is not reference map, so it cannot be modified with
1.199 + /// the subscript operator.
1.200 ///
1.201 /// \tparam GR The graph type.
1.202 /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1.203 @@ -1923,7 +1942,7 @@
1.204 typedef typename ItemSetTraits<GR, K>::
1.205 template Map<V>::Type Map;
1.206
1.207 - typedef std::map<V, K> Container;
1.208 + typedef std::multimap<V, K> Container;
1.209 Container _inv_map;
1.210
1.211 public:
1.212 @@ -1945,54 +1964,66 @@
1.213
1.214 /// \brief Forward iterator for values.
1.215 ///
1.216 - /// This iterator is an stl compatible forward
1.217 + /// This iterator is an STL compatible forward
1.218 /// iterator on the values of the map. The values can
1.219 /// be accessed in the <tt>[beginValue, endValue)</tt> range.
1.220 - class ValueIterator
1.221 + /// They are considered with multiplicity, so each value is
1.222 + /// traversed for each item it is assigned to.
1.223 + class ValueIt
1.224 : public std::iterator<std::forward_iterator_tag, Value> {
1.225 friend class CrossRefMap;
1.226 private:
1.227 - ValueIterator(typename Container::const_iterator _it)
1.228 + ValueIt(typename Container::const_iterator _it)
1.229 : it(_it) {}
1.230 public:
1.231
1.232 - ValueIterator() {}
1.233 -
1.234 - ValueIterator& operator++() { ++it; return *this; }
1.235 - ValueIterator operator++(int) {
1.236 - ValueIterator tmp(*this);
1.237 + /// Constructor
1.238 + ValueIt() {}
1.239 +
1.240 + /// \e
1.241 + ValueIt& operator++() { ++it; return *this; }
1.242 + /// \e
1.243 + ValueIt operator++(int) {
1.244 + ValueIt tmp(*this);
1.245 operator++();
1.246 return tmp;
1.247 }
1.248
1.249 + /// \e
1.250 const Value& operator*() const { return it->first; }
1.251 + /// \e
1.252 const Value* operator->() const { return &(it->first); }
1.253
1.254 - bool operator==(ValueIterator jt) const { return it == jt.it; }
1.255 - bool operator!=(ValueIterator jt) const { return it != jt.it; }
1.256 + /// \e
1.257 + bool operator==(ValueIt jt) const { return it == jt.it; }
1.258 + /// \e
1.259 + bool operator!=(ValueIt jt) const { return it != jt.it; }
1.260
1.261 private:
1.262 typename Container::const_iterator it;
1.263 };
1.264 +
1.265 + /// Alias for \c ValueIt
1.266 + typedef ValueIt ValueIterator;
1.267
1.268 /// \brief Returns an iterator to the first value.
1.269 ///
1.270 - /// Returns an stl compatible iterator to the
1.271 + /// Returns an STL compatible iterator to the
1.272 /// first value of the map. The values of the
1.273 /// map can be accessed in the <tt>[beginValue, endValue)</tt>
1.274 /// range.
1.275 - ValueIterator beginValue() const {
1.276 - return ValueIterator(_inv_map.begin());
1.277 + ValueIt beginValue() const {
1.278 + return ValueIt(_inv_map.begin());
1.279 }
1.280
1.281 /// \brief Returns an iterator after the last value.
1.282 ///
1.283 - /// Returns an stl compatible iterator after the
1.284 + /// Returns an STL compatible iterator after the
1.285 /// last value of the map. The values of the
1.286 /// map can be accessed in the <tt>[beginValue, endValue)</tt>
1.287 /// range.
1.288 - ValueIterator endValue() const {
1.289 - return ValueIterator(_inv_map.end());
1.290 + ValueIt endValue() const {
1.291 + return ValueIt(_inv_map.end());
1.292 }
1.293
1.294 /// \brief Sets the value associated with the given key.
1.295 @@ -2000,11 +2031,15 @@
1.296 /// Sets the value associated with the given key.
1.297 void set(const Key& key, const Value& val) {
1.298 Value oldval = Map::operator[](key);
1.299 - typename Container::iterator it = _inv_map.find(oldval);
1.300 - if (it != _inv_map.end() && it->second == key) {
1.301 - _inv_map.erase(it);
1.302 + typename Container::iterator it;
1.303 + for (it = _inv_map.equal_range(oldval).first;
1.304 + it != _inv_map.equal_range(oldval).second; ++it) {
1.305 + if (it->second == key) {
1.306 + _inv_map.erase(it);
1.307 + break;
1.308 + }
1.309 }
1.310 - _inv_map.insert(make_pair(val, key));
1.311 + _inv_map.insert(std::make_pair(val, key));
1.312 Map::set(key, val);
1.313 }
1.314
1.315 @@ -2016,13 +2051,24 @@
1.316 return Map::operator[](key);
1.317 }
1.318
1.319 - /// \brief Gives back the item by its value.
1.320 + /// \brief Gives back an item by its value.
1.321 ///
1.322 - /// Gives back the item by its value.
1.323 - Key operator()(const Value& key) const {
1.324 - typename Container::const_iterator it = _inv_map.find(key);
1.325 + /// This function gives back an item that is assigned to
1.326 + /// the given value or \c INVALID if no such item exists.
1.327 + /// If there are more items with the same associated value,
1.328 + /// only one of them is returned.
1.329 + Key operator()(const Value& val) const {
1.330 + typename Container::const_iterator it = _inv_map.find(val);
1.331 return it != _inv_map.end() ? it->second : INVALID;
1.332 }
1.333 +
1.334 + /// \brief Returns the number of items with the given value.
1.335 + ///
1.336 + /// This function returns the number of items with the given value
1.337 + /// associated with it.
1.338 + int count(const Value &val) const {
1.339 + return _inv_map.count(val);
1.340 + }
1.341
1.342 protected:
1.343
1.344 @@ -2032,9 +2078,13 @@
1.345 /// \c AlterationNotifier.
1.346 virtual void erase(const Key& key) {
1.347 Value val = Map::operator[](key);
1.348 - typename Container::iterator it = _inv_map.find(val);
1.349 - if (it != _inv_map.end() && it->second == key) {
1.350 - _inv_map.erase(it);
1.351 + typename Container::iterator it;
1.352 + for (it = _inv_map.equal_range(val).first;
1.353 + it != _inv_map.equal_range(val).second; ++it) {
1.354 + if (it->second == key) {
1.355 + _inv_map.erase(it);
1.356 + break;
1.357 + }
1.358 }
1.359 Map::erase(key);
1.360 }
1.361 @@ -2046,9 +2096,13 @@
1.362 virtual void erase(const std::vector<Key>& keys) {
1.363 for (int i = 0; i < int(keys.size()); ++i) {
1.364 Value val = Map::operator[](keys[i]);
1.365 - typename Container::iterator it = _inv_map.find(val);
1.366 - if (it != _inv_map.end() && it->second == keys[i]) {
1.367 - _inv_map.erase(it);
1.368 + typename Container::iterator it;
1.369 + for (it = _inv_map.equal_range(val).first;
1.370 + it != _inv_map.equal_range(val).second; ++it) {
1.371 + if (it->second == keys[i]) {
1.372 + _inv_map.erase(it);
1.373 + break;
1.374 + }
1.375 }
1.376 }
1.377 Map::erase(keys);
1.378 @@ -2065,10 +2119,12 @@
1.379
1.380 public:
1.381
1.382 - /// \brief The inverse map type.
1.383 + /// \brief The inverse map type of CrossRefMap.
1.384 ///
1.385 - /// The inverse of this map. The subscript operator of the map
1.386 - /// gives back the item that was last assigned to the value.
1.387 + /// The inverse map type of CrossRefMap. The subscript operator gives
1.388 + /// back an item by its value.
1.389 + /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
1.390 + /// \see inverse()
1.391 class InverseMap {
1.392 public:
1.393 /// \brief Constructor
1.394 @@ -2084,8 +2140,9 @@
1.395
1.396 /// \brief Subscript operator.
1.397 ///
1.398 - /// Subscript operator. It gives back the item
1.399 - /// that was last assigned to the given value.
1.400 + /// Subscript operator. It gives back an item
1.401 + /// that is assigned to the given value or \c INVALID
1.402 + /// if no such item exists.
1.403 Value operator[](const Key& key) const {
1.404 return _inverted(key);
1.405 }
1.406 @@ -2094,20 +2151,20 @@
1.407 const CrossRefMap& _inverted;
1.408 };
1.409
1.410 - /// \brief It gives back the read-only inverse map.
1.411 + /// \brief Gives back the inverse of the map.
1.412 ///
1.413 - /// It gives back the read-only inverse map.
1.414 + /// Gives back the inverse of the CrossRefMap.
1.415 InverseMap inverse() const {
1.416 return InverseMap(*this);
1.417 }
1.418
1.419 };
1.420
1.421 - /// \brief Provides continuous and unique ID for the
1.422 + /// \brief Provides continuous and unique id for the
1.423 /// items of a graph.
1.424 ///
1.425 /// RangeIdMap provides a unique and continuous
1.426 - /// ID for each item of a given type (\c Node, \c Arc or
1.427 + /// id for each item of a given type (\c Node, \c Arc or
1.428 /// \c Edge) in a graph. This id is
1.429 /// - \b unique: different items get different ids,
1.430 /// - \b continuous: the range of the ids is the set of integers
1.431 @@ -2118,7 +2175,7 @@
1.432 /// Thus this id is not (necessarily) the same as what can get using
1.433 /// the \c id() function of the graph or \ref IdMap.
1.434 /// This map can be inverted with its member class \c InverseMap,
1.435 - /// or with the \c operator() member.
1.436 + /// or with the \c operator()() member.
1.437 ///
1.438 /// \tparam GR The graph type.
1.439 /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1.440 @@ -2246,16 +2303,16 @@
1.441 _inv_map[pi] = q;
1.442 }
1.443
1.444 - /// \brief Gives back the \e RangeId of the item
1.445 + /// \brief Gives back the \e range \e id of the item
1.446 ///
1.447 - /// Gives back the \e RangeId of the item.
1.448 + /// Gives back the \e range \e id of the item.
1.449 int operator[](const Item& item) const {
1.450 return Map::operator[](item);
1.451 }
1.452
1.453 - /// \brief Gives back the item belonging to a \e RangeId
1.454 - ///
1.455 - /// Gives back the item belonging to a \e RangeId.
1.456 + /// \brief Gives back the item belonging to a \e range \e id
1.457 + ///
1.458 + /// Gives back the item belonging to the given \e range \e id.
1.459 Item operator()(int id) const {
1.460 return _inv_map[id];
1.461 }
1.462 @@ -2269,7 +2326,9 @@
1.463
1.464 /// \brief The inverse map type of RangeIdMap.
1.465 ///
1.466 - /// The inverse map type of RangeIdMap.
1.467 + /// The inverse map type of RangeIdMap. The subscript operator gives
1.468 + /// back an item by its \e range \e id.
1.469 + /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
1.470 class InverseMap {
1.471 public:
1.472 /// \brief Constructor
1.473 @@ -2287,7 +2346,7 @@
1.474 /// \brief Subscript operator.
1.475 ///
1.476 /// Subscript operator. It gives back the item
1.477 - /// that the descriptor currently belongs to.
1.478 + /// that the given \e range \e id currently belongs to.
1.479 Value operator[](const Key& key) const {
1.480 return _inverted(key);
1.481 }
1.482 @@ -2305,12 +2364,932 @@
1.483
1.484 /// \brief Gives back the inverse of the map.
1.485 ///
1.486 - /// Gives back the inverse of the map.
1.487 + /// Gives back the inverse of the RangeIdMap.
1.488 const InverseMap inverse() const {
1.489 return InverseMap(*this);
1.490 }
1.491 };
1.492
1.493 + /// \brief Returns a \c RangeIdMap class.
1.494 + ///
1.495 + /// This function just returns an \c RangeIdMap class.
1.496 + /// \relates RangeIdMap
1.497 + template <typename K, typename GR>
1.498 + inline RangeIdMap<GR, K> rangeIdMap(const GR& graph) {
1.499 + return RangeIdMap<GR, K>(graph);
1.500 + }
1.501 +
1.502 + /// \brief Dynamic iterable \c bool map.
1.503 + ///
1.504 + /// This class provides a special graph map type which can store a
1.505 + /// \c bool value for graph items (\c Node, \c Arc or \c Edge).
1.506 + /// For both \c true and \c false values it is possible to iterate on
1.507 + /// the keys mapped to the value.
1.508 + ///
1.509 + /// This type is a reference map, so it can be modified with the
1.510 + /// subscript operator.
1.511 + ///
1.512 + /// \tparam GR The graph type.
1.513 + /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1.514 + /// \c GR::Edge).
1.515 + ///
1.516 + /// \see IterableIntMap, IterableValueMap
1.517 + /// \see CrossRefMap
1.518 + template <typename GR, typename K>
1.519 + class IterableBoolMap
1.520 + : protected ItemSetTraits<GR, K>::template Map<int>::Type {
1.521 + private:
1.522 + typedef GR Graph;
1.523 +
1.524 + typedef typename ItemSetTraits<GR, K>::ItemIt KeyIt;
1.525 + typedef typename ItemSetTraits<GR, K>::template Map<int>::Type Parent;
1.526 +
1.527 + std::vector<K> _array;
1.528 + int _sep;
1.529 +
1.530 + public:
1.531 +
1.532 + /// Indicates that the map is reference map.
1.533 + typedef True ReferenceMapTag;
1.534 +
1.535 + /// The key type
1.536 + typedef K Key;
1.537 + /// The value type
1.538 + typedef bool Value;
1.539 + /// The const reference type.
1.540 + typedef const Value& ConstReference;
1.541 +
1.542 + private:
1.543 +
1.544 + int position(const Key& key) const {
1.545 + return Parent::operator[](key);
1.546 + }
1.547 +
1.548 + public:
1.549 +
1.550 + /// \brief Reference to the value of the map.
1.551 + ///
1.552 + /// This class is similar to the \c bool type. It can be converted to
1.553 + /// \c bool and it provides the same operators.
1.554 + class Reference {
1.555 + friend class IterableBoolMap;
1.556 + private:
1.557 + Reference(IterableBoolMap& map, const Key& key)
1.558 + : _key(key), _map(map) {}
1.559 + public:
1.560 +
1.561 + Reference& operator=(const Reference& value) {
1.562 + _map.set(_key, static_cast<bool>(value));
1.563 + return *this;
1.564 + }
1.565 +
1.566 + operator bool() const {
1.567 + return static_cast<const IterableBoolMap&>(_map)[_key];
1.568 + }
1.569 +
1.570 + Reference& operator=(bool value) {
1.571 + _map.set(_key, value);
1.572 + return *this;
1.573 + }
1.574 + Reference& operator&=(bool value) {
1.575 + _map.set(_key, _map[_key] & value);
1.576 + return *this;
1.577 + }
1.578 + Reference& operator|=(bool value) {
1.579 + _map.set(_key, _map[_key] | value);
1.580 + return *this;
1.581 + }
1.582 + Reference& operator^=(bool value) {
1.583 + _map.set(_key, _map[_key] ^ value);
1.584 + return *this;
1.585 + }
1.586 + private:
1.587 + Key _key;
1.588 + IterableBoolMap& _map;
1.589 + };
1.590 +
1.591 + /// \brief Constructor of the map with a default value.
1.592 + ///
1.593 + /// Constructor of the map with a default value.
1.594 + explicit IterableBoolMap(const Graph& graph, bool def = false)
1.595 + : Parent(graph) {
1.596 + typename Parent::Notifier* nf = Parent::notifier();
1.597 + Key it;
1.598 + for (nf->first(it); it != INVALID; nf->next(it)) {
1.599 + Parent::set(it, _array.size());
1.600 + _array.push_back(it);
1.601 + }
1.602 + _sep = (def ? _array.size() : 0);
1.603 + }
1.604 +
1.605 + /// \brief Const subscript operator of the map.
1.606 + ///
1.607 + /// Const subscript operator of the map.
1.608 + bool operator[](const Key& key) const {
1.609 + return position(key) < _sep;
1.610 + }
1.611 +
1.612 + /// \brief Subscript operator of the map.
1.613 + ///
1.614 + /// Subscript operator of the map.
1.615 + Reference operator[](const Key& key) {
1.616 + return Reference(*this, key);
1.617 + }
1.618 +
1.619 + /// \brief Set operation of the map.
1.620 + ///
1.621 + /// Set operation of the map.
1.622 + void set(const Key& key, bool value) {
1.623 + int pos = position(key);
1.624 + if (value) {
1.625 + if (pos < _sep) return;
1.626 + Key tmp = _array[_sep];
1.627 + _array[_sep] = key;
1.628 + Parent::set(key, _sep);
1.629 + _array[pos] = tmp;
1.630 + Parent::set(tmp, pos);
1.631 + ++_sep;
1.632 + } else {
1.633 + if (pos >= _sep) return;
1.634 + --_sep;
1.635 + Key tmp = _array[_sep];
1.636 + _array[_sep] = key;
1.637 + Parent::set(key, _sep);
1.638 + _array[pos] = tmp;
1.639 + Parent::set(tmp, pos);
1.640 + }
1.641 + }
1.642 +
1.643 + /// \brief Set all items.
1.644 + ///
1.645 + /// Set all items in the map.
1.646 + /// \note Constant time operation.
1.647 + void setAll(bool value) {
1.648 + _sep = (value ? _array.size() : 0);
1.649 + }
1.650 +
1.651 + /// \brief Returns the number of the keys mapped to \c true.
1.652 + ///
1.653 + /// Returns the number of the keys mapped to \c true.
1.654 + int trueNum() const {
1.655 + return _sep;
1.656 + }
1.657 +
1.658 + /// \brief Returns the number of the keys mapped to \c false.
1.659 + ///
1.660 + /// Returns the number of the keys mapped to \c false.
1.661 + int falseNum() const {
1.662 + return _array.size() - _sep;
1.663 + }
1.664 +
1.665 + /// \brief Iterator for the keys mapped to \c true.
1.666 + ///
1.667 + /// Iterator for the keys mapped to \c true. It works
1.668 + /// like a graph item iterator, it can be converted to
1.669 + /// the key type of the map, incremented with \c ++ operator, and
1.670 + /// if the iterator leaves the last valid key, it will be equal to
1.671 + /// \c INVALID.
1.672 + class TrueIt : public Key {
1.673 + public:
1.674 + typedef Key Parent;
1.675 +
1.676 + /// \brief Creates an iterator.
1.677 + ///
1.678 + /// Creates an iterator. It iterates on the
1.679 + /// keys mapped to \c true.
1.680 + /// \param map The IterableBoolMap.
1.681 + explicit TrueIt(const IterableBoolMap& map)
1.682 + : Parent(map._sep > 0 ? map._array[map._sep - 1] : INVALID),
1.683 + _map(&map) {}
1.684 +
1.685 + /// \brief Invalid constructor \& conversion.
1.686 + ///
1.687 + /// This constructor initializes the iterator to be invalid.
1.688 + /// \sa Invalid for more details.
1.689 + TrueIt(Invalid) : Parent(INVALID), _map(0) {}
1.690 +
1.691 + /// \brief Increment operator.
1.692 + ///
1.693 + /// Increment operator.
1.694 + TrueIt& operator++() {
1.695 + int pos = _map->position(*this);
1.696 + Parent::operator=(pos > 0 ? _map->_array[pos - 1] : INVALID);
1.697 + return *this;
1.698 + }
1.699 +
1.700 + private:
1.701 + const IterableBoolMap* _map;
1.702 + };
1.703 +
1.704 + /// \brief Iterator for the keys mapped to \c false.
1.705 + ///
1.706 + /// Iterator for the keys mapped to \c false. It works
1.707 + /// like a graph item iterator, it can be converted to
1.708 + /// the key type of the map, incremented with \c ++ operator, and
1.709 + /// if the iterator leaves the last valid key, it will be equal to
1.710 + /// \c INVALID.
1.711 + class FalseIt : public Key {
1.712 + public:
1.713 + typedef Key Parent;
1.714 +
1.715 + /// \brief Creates an iterator.
1.716 + ///
1.717 + /// Creates an iterator. It iterates on the
1.718 + /// keys mapped to \c false.
1.719 + /// \param map The IterableBoolMap.
1.720 + explicit FalseIt(const IterableBoolMap& map)
1.721 + : Parent(map._sep < int(map._array.size()) ?
1.722 + map._array.back() : INVALID), _map(&map) {}
1.723 +
1.724 + /// \brief Invalid constructor \& conversion.
1.725 + ///
1.726 + /// This constructor initializes the iterator to be invalid.
1.727 + /// \sa Invalid for more details.
1.728 + FalseIt(Invalid) : Parent(INVALID), _map(0) {}
1.729 +
1.730 + /// \brief Increment operator.
1.731 + ///
1.732 + /// Increment operator.
1.733 + FalseIt& operator++() {
1.734 + int pos = _map->position(*this);
1.735 + Parent::operator=(pos > _map->_sep ? _map->_array[pos - 1] : INVALID);
1.736 + return *this;
1.737 + }
1.738 +
1.739 + private:
1.740 + const IterableBoolMap* _map;
1.741 + };
1.742 +
1.743 + /// \brief Iterator for the keys mapped to a given value.
1.744 + ///
1.745 + /// Iterator for the keys mapped to a given value. It works
1.746 + /// like a graph item iterator, it can be converted to
1.747 + /// the key type of the map, incremented with \c ++ operator, and
1.748 + /// if the iterator leaves the last valid key, it will be equal to
1.749 + /// \c INVALID.
1.750 + class ItemIt : public Key {
1.751 + public:
1.752 + typedef Key Parent;
1.753 +
1.754 + /// \brief Creates an iterator with a value.
1.755 + ///
1.756 + /// Creates an iterator with a value. It iterates on the
1.757 + /// keys mapped to the given value.
1.758 + /// \param map The IterableBoolMap.
1.759 + /// \param value The value.
1.760 + ItemIt(const IterableBoolMap& map, bool value)
1.761 + : Parent(value ?
1.762 + (map._sep > 0 ?
1.763 + map._array[map._sep - 1] : INVALID) :
1.764 + (map._sep < int(map._array.size()) ?
1.765 + map._array.back() : INVALID)), _map(&map) {}
1.766 +
1.767 + /// \brief Invalid constructor \& conversion.
1.768 + ///
1.769 + /// This constructor initializes the iterator to be invalid.
1.770 + /// \sa Invalid for more details.
1.771 + ItemIt(Invalid) : Parent(INVALID), _map(0) {}
1.772 +
1.773 + /// \brief Increment operator.
1.774 + ///
1.775 + /// Increment operator.
1.776 + ItemIt& operator++() {
1.777 + int pos = _map->position(*this);
1.778 + int _sep = pos >= _map->_sep ? _map->_sep : 0;
1.779 + Parent::operator=(pos > _sep ? _map->_array[pos - 1] : INVALID);
1.780 + return *this;
1.781 + }
1.782 +
1.783 + private:
1.784 + const IterableBoolMap* _map;
1.785 + };
1.786 +
1.787 + protected:
1.788 +
1.789 + virtual void add(const Key& key) {
1.790 + Parent::add(key);
1.791 + Parent::set(key, _array.size());
1.792 + _array.push_back(key);
1.793 + }
1.794 +
1.795 + virtual void add(const std::vector<Key>& keys) {
1.796 + Parent::add(keys);
1.797 + for (int i = 0; i < int(keys.size()); ++i) {
1.798 + Parent::set(keys[i], _array.size());
1.799 + _array.push_back(keys[i]);
1.800 + }
1.801 + }
1.802 +
1.803 + virtual void erase(const Key& key) {
1.804 + int pos = position(key);
1.805 + if (pos < _sep) {
1.806 + --_sep;
1.807 + Parent::set(_array[_sep], pos);
1.808 + _array[pos] = _array[_sep];
1.809 + Parent::set(_array.back(), _sep);
1.810 + _array[_sep] = _array.back();
1.811 + _array.pop_back();
1.812 + } else {
1.813 + Parent::set(_array.back(), pos);
1.814 + _array[pos] = _array.back();
1.815 + _array.pop_back();
1.816 + }
1.817 + Parent::erase(key);
1.818 + }
1.819 +
1.820 + virtual void erase(const std::vector<Key>& keys) {
1.821 + for (int i = 0; i < int(keys.size()); ++i) {
1.822 + int pos = position(keys[i]);
1.823 + if (pos < _sep) {
1.824 + --_sep;
1.825 + Parent::set(_array[_sep], pos);
1.826 + _array[pos] = _array[_sep];
1.827 + Parent::set(_array.back(), _sep);
1.828 + _array[_sep] = _array.back();
1.829 + _array.pop_back();
1.830 + } else {
1.831 + Parent::set(_array.back(), pos);
1.832 + _array[pos] = _array.back();
1.833 + _array.pop_back();
1.834 + }
1.835 + }
1.836 + Parent::erase(keys);
1.837 + }
1.838 +
1.839 + virtual void build() {
1.840 + Parent::build();
1.841 + typename Parent::Notifier* nf = Parent::notifier();
1.842 + Key it;
1.843 + for (nf->first(it); it != INVALID; nf->next(it)) {
1.844 + Parent::set(it, _array.size());
1.845 + _array.push_back(it);
1.846 + }
1.847 + _sep = 0;
1.848 + }
1.849 +
1.850 + virtual void clear() {
1.851 + _array.clear();
1.852 + _sep = 0;
1.853 + Parent::clear();
1.854 + }
1.855 +
1.856 + };
1.857 +
1.858 +
1.859 + namespace _maps_bits {
1.860 + template <typename Item>
1.861 + struct IterableIntMapNode {
1.862 + IterableIntMapNode() : value(-1) {}
1.863 + IterableIntMapNode(int _value) : value(_value) {}
1.864 + Item prev, next;
1.865 + int value;
1.866 + };
1.867 + }
1.868 +
1.869 + /// \brief Dynamic iterable integer map.
1.870 + ///
1.871 + /// This class provides a special graph map type which can store an
1.872 + /// integer value for graph items (\c Node, \c Arc or \c Edge).
1.873 + /// For each non-negative value it is possible to iterate on the keys
1.874 + /// mapped to the value.
1.875 + ///
1.876 + /// This map is intended to be used with small integer values, for which
1.877 + /// it is efficient, and supports iteration only for non-negative values.
1.878 + /// If you need large values and/or iteration for negative integers,
1.879 + /// consider to use \ref IterableValueMap instead.
1.880 + ///
1.881 + /// This type is a reference map, so it can be modified with the
1.882 + /// subscript operator.
1.883 + ///
1.884 + /// \note The size of the data structure depends on the largest
1.885 + /// value in the map.
1.886 + ///
1.887 + /// \tparam GR The graph type.
1.888 + /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1.889 + /// \c GR::Edge).
1.890 + ///
1.891 + /// \see IterableBoolMap, IterableValueMap
1.892 + /// \see CrossRefMap
1.893 + template <typename GR, typename K>
1.894 + class IterableIntMap
1.895 + : protected ItemSetTraits<GR, K>::
1.896 + template Map<_maps_bits::IterableIntMapNode<K> >::Type {
1.897 + public:
1.898 + typedef typename ItemSetTraits<GR, K>::
1.899 + template Map<_maps_bits::IterableIntMapNode<K> >::Type Parent;
1.900 +
1.901 + /// The key type
1.902 + typedef K Key;
1.903 + /// The value type
1.904 + typedef int Value;
1.905 + /// The graph type
1.906 + typedef GR Graph;
1.907 +
1.908 + /// \brief Constructor of the map.
1.909 + ///
1.910 + /// Constructor of the map. It sets all values to -1.
1.911 + explicit IterableIntMap(const Graph& graph)
1.912 + : Parent(graph) {}
1.913 +
1.914 + /// \brief Constructor of the map with a given value.
1.915 + ///
1.916 + /// Constructor of the map with a given value.
1.917 + explicit IterableIntMap(const Graph& graph, int value)
1.918 + : Parent(graph, _maps_bits::IterableIntMapNode<K>(value)) {
1.919 + if (value >= 0) {
1.920 + for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
1.921 + lace(it);
1.922 + }
1.923 + }
1.924 + }
1.925 +
1.926 + private:
1.927 +
1.928 + void unlace(const Key& key) {
1.929 + typename Parent::Value& node = Parent::operator[](key);
1.930 + if (node.value < 0) return;
1.931 + if (node.prev != INVALID) {
1.932 + Parent::operator[](node.prev).next = node.next;
1.933 + } else {
1.934 + _first[node.value] = node.next;
1.935 + }
1.936 + if (node.next != INVALID) {
1.937 + Parent::operator[](node.next).prev = node.prev;
1.938 + }
1.939 + while (!_first.empty() && _first.back() == INVALID) {
1.940 + _first.pop_back();
1.941 + }
1.942 + }
1.943 +
1.944 + void lace(const Key& key) {
1.945 + typename Parent::Value& node = Parent::operator[](key);
1.946 + if (node.value < 0) return;
1.947 + if (node.value >= int(_first.size())) {
1.948 + _first.resize(node.value + 1, INVALID);
1.949 + }
1.950 + node.prev = INVALID;
1.951 + node.next = _first[node.value];
1.952 + if (node.next != INVALID) {
1.953 + Parent::operator[](node.next).prev = key;
1.954 + }
1.955 + _first[node.value] = key;
1.956 + }
1.957 +
1.958 + public:
1.959 +
1.960 + /// Indicates that the map is reference map.
1.961 + typedef True ReferenceMapTag;
1.962 +
1.963 + /// \brief Reference to the value of the map.
1.964 + ///
1.965 + /// This class is similar to the \c int type. It can
1.966 + /// be converted to \c int and it has the same operators.
1.967 + class Reference {
1.968 + friend class IterableIntMap;
1.969 + private:
1.970 + Reference(IterableIntMap& map, const Key& key)
1.971 + : _key(key), _map(map) {}
1.972 + public:
1.973 +
1.974 + Reference& operator=(const Reference& value) {
1.975 + _map.set(_key, static_cast<const int&>(value));
1.976 + return *this;
1.977 + }
1.978 +
1.979 + operator const int&() const {
1.980 + return static_cast<const IterableIntMap&>(_map)[_key];
1.981 + }
1.982 +
1.983 + Reference& operator=(int value) {
1.984 + _map.set(_key, value);
1.985 + return *this;
1.986 + }
1.987 + Reference& operator++() {
1.988 + _map.set(_key, _map[_key] + 1);
1.989 + return *this;
1.990 + }
1.991 + int operator++(int) {
1.992 + int value = _map[_key];
1.993 + _map.set(_key, value + 1);
1.994 + return value;
1.995 + }
1.996 + Reference& operator--() {
1.997 + _map.set(_key, _map[_key] - 1);
1.998 + return *this;
1.999 + }
1.1000 + int operator--(int) {
1.1001 + int value = _map[_key];
1.1002 + _map.set(_key, value - 1);
1.1003 + return value;
1.1004 + }
1.1005 + Reference& operator+=(int value) {
1.1006 + _map.set(_key, _map[_key] + value);
1.1007 + return *this;
1.1008 + }
1.1009 + Reference& operator-=(int value) {
1.1010 + _map.set(_key, _map[_key] - value);
1.1011 + return *this;
1.1012 + }
1.1013 + Reference& operator*=(int value) {
1.1014 + _map.set(_key, _map[_key] * value);
1.1015 + return *this;
1.1016 + }
1.1017 + Reference& operator/=(int value) {
1.1018 + _map.set(_key, _map[_key] / value);
1.1019 + return *this;
1.1020 + }
1.1021 + Reference& operator%=(int value) {
1.1022 + _map.set(_key, _map[_key] % value);
1.1023 + return *this;
1.1024 + }
1.1025 + Reference& operator&=(int value) {
1.1026 + _map.set(_key, _map[_key] & value);
1.1027 + return *this;
1.1028 + }
1.1029 + Reference& operator|=(int value) {
1.1030 + _map.set(_key, _map[_key] | value);
1.1031 + return *this;
1.1032 + }
1.1033 + Reference& operator^=(int value) {
1.1034 + _map.set(_key, _map[_key] ^ value);
1.1035 + return *this;
1.1036 + }
1.1037 + Reference& operator<<=(int value) {
1.1038 + _map.set(_key, _map[_key] << value);
1.1039 + return *this;
1.1040 + }
1.1041 + Reference& operator>>=(int value) {
1.1042 + _map.set(_key, _map[_key] >> value);
1.1043 + return *this;
1.1044 + }
1.1045 +
1.1046 + private:
1.1047 + Key _key;
1.1048 + IterableIntMap& _map;
1.1049 + };
1.1050 +
1.1051 + /// The const reference type.
1.1052 + typedef const Value& ConstReference;
1.1053 +
1.1054 + /// \brief Gives back the maximal value plus one.
1.1055 + ///
1.1056 + /// Gives back the maximal value plus one.
1.1057 + int size() const {
1.1058 + return _first.size();
1.1059 + }
1.1060 +
1.1061 + /// \brief Set operation of the map.
1.1062 + ///
1.1063 + /// Set operation of the map.
1.1064 + void set(const Key& key, const Value& value) {
1.1065 + unlace(key);
1.1066 + Parent::operator[](key).value = value;
1.1067 + lace(key);
1.1068 + }
1.1069 +
1.1070 + /// \brief Const subscript operator of the map.
1.1071 + ///
1.1072 + /// Const subscript operator of the map.
1.1073 + const Value& operator[](const Key& key) const {
1.1074 + return Parent::operator[](key).value;
1.1075 + }
1.1076 +
1.1077 + /// \brief Subscript operator of the map.
1.1078 + ///
1.1079 + /// Subscript operator of the map.
1.1080 + Reference operator[](const Key& key) {
1.1081 + return Reference(*this, key);
1.1082 + }
1.1083 +
1.1084 + /// \brief Iterator for the keys with the same value.
1.1085 + ///
1.1086 + /// Iterator for the keys with the same value. It works
1.1087 + /// like a graph item iterator, it can be converted to
1.1088 + /// the item type of the map, incremented with \c ++ operator, and
1.1089 + /// if the iterator leaves the last valid item, it will be equal to
1.1090 + /// \c INVALID.
1.1091 + class ItemIt : public Key {
1.1092 + public:
1.1093 + typedef Key Parent;
1.1094 +
1.1095 + /// \brief Invalid constructor \& conversion.
1.1096 + ///
1.1097 + /// This constructor initializes the iterator to be invalid.
1.1098 + /// \sa Invalid for more details.
1.1099 + ItemIt(Invalid) : Parent(INVALID), _map(0) {}
1.1100 +
1.1101 + /// \brief Creates an iterator with a value.
1.1102 + ///
1.1103 + /// Creates an iterator with a value. It iterates on the
1.1104 + /// keys mapped to the given value.
1.1105 + /// \param map The IterableIntMap.
1.1106 + /// \param value The value.
1.1107 + ItemIt(const IterableIntMap& map, int value) : _map(&map) {
1.1108 + if (value < 0 || value >= int(_map->_first.size())) {
1.1109 + Parent::operator=(INVALID);
1.1110 + } else {
1.1111 + Parent::operator=(_map->_first[value]);
1.1112 + }
1.1113 + }
1.1114 +
1.1115 + /// \brief Increment operator.
1.1116 + ///
1.1117 + /// Increment operator.
1.1118 + ItemIt& operator++() {
1.1119 + Parent::operator=(_map->IterableIntMap::Parent::
1.1120 + operator[](static_cast<Parent&>(*this)).next);
1.1121 + return *this;
1.1122 + }
1.1123 +
1.1124 + private:
1.1125 + const IterableIntMap* _map;
1.1126 + };
1.1127 +
1.1128 + protected:
1.1129 +
1.1130 + virtual void erase(const Key& key) {
1.1131 + unlace(key);
1.1132 + Parent::erase(key);
1.1133 + }
1.1134 +
1.1135 + virtual void erase(const std::vector<Key>& keys) {
1.1136 + for (int i = 0; i < int(keys.size()); ++i) {
1.1137 + unlace(keys[i]);
1.1138 + }
1.1139 + Parent::erase(keys);
1.1140 + }
1.1141 +
1.1142 + virtual void clear() {
1.1143 + _first.clear();
1.1144 + Parent::clear();
1.1145 + }
1.1146 +
1.1147 + private:
1.1148 + std::vector<Key> _first;
1.1149 + };
1.1150 +
1.1151 + namespace _maps_bits {
1.1152 + template <typename Item, typename Value>
1.1153 + struct IterableValueMapNode {
1.1154 + IterableValueMapNode(Value _value = Value()) : value(_value) {}
1.1155 + Item prev, next;
1.1156 + Value value;
1.1157 + };
1.1158 + }
1.1159 +
1.1160 + /// \brief Dynamic iterable map for comparable values.
1.1161 + ///
1.1162 + /// This class provides a special graph map type which can store a
1.1163 + /// comparable value for graph items (\c Node, \c Arc or \c Edge).
1.1164 + /// For each value it is possible to iterate on the keys mapped to
1.1165 + /// the value (\c ItemIt), and the values of the map can be accessed
1.1166 + /// with an STL compatible forward iterator (\c ValueIt).
1.1167 + /// The map stores a linked list for each value, which contains
1.1168 + /// the items mapped to the value, and the used values are stored
1.1169 + /// in balanced binary tree (\c std::map).
1.1170 + ///
1.1171 + /// \ref IterableBoolMap and \ref IterableIntMap are similar classes
1.1172 + /// specialized for \c bool and \c int values, respectively.
1.1173 + ///
1.1174 + /// This type is not reference map, so it cannot be modified with
1.1175 + /// the subscript operator.
1.1176 + ///
1.1177 + /// \tparam GR The graph type.
1.1178 + /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1.1179 + /// \c GR::Edge).
1.1180 + /// \tparam V The value type of the map. It can be any comparable
1.1181 + /// value type.
1.1182 + ///
1.1183 + /// \see IterableBoolMap, IterableIntMap
1.1184 + /// \see CrossRefMap
1.1185 + template <typename GR, typename K, typename V>
1.1186 + class IterableValueMap
1.1187 + : protected ItemSetTraits<GR, K>::
1.1188 + template Map<_maps_bits::IterableValueMapNode<K, V> >::Type {
1.1189 + public:
1.1190 + typedef typename ItemSetTraits<GR, K>::
1.1191 + template Map<_maps_bits::IterableValueMapNode<K, V> >::Type Parent;
1.1192 +
1.1193 + /// The key type
1.1194 + typedef K Key;
1.1195 + /// The value type
1.1196 + typedef V Value;
1.1197 + /// The graph type
1.1198 + typedef GR Graph;
1.1199 +
1.1200 + public:
1.1201 +
1.1202 + /// \brief Constructor of the map with a given value.
1.1203 + ///
1.1204 + /// Constructor of the map with a given value.
1.1205 + explicit IterableValueMap(const Graph& graph,
1.1206 + const Value& value = Value())
1.1207 + : Parent(graph, _maps_bits::IterableValueMapNode<K, V>(value)) {
1.1208 + for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
1.1209 + lace(it);
1.1210 + }
1.1211 + }
1.1212 +
1.1213 + protected:
1.1214 +
1.1215 + void unlace(const Key& key) {
1.1216 + typename Parent::Value& node = Parent::operator[](key);
1.1217 + if (node.prev != INVALID) {
1.1218 + Parent::operator[](node.prev).next = node.next;
1.1219 + } else {
1.1220 + if (node.next != INVALID) {
1.1221 + _first[node.value] = node.next;
1.1222 + } else {
1.1223 + _first.erase(node.value);
1.1224 + }
1.1225 + }
1.1226 + if (node.next != INVALID) {
1.1227 + Parent::operator[](node.next).prev = node.prev;
1.1228 + }
1.1229 + }
1.1230 +
1.1231 + void lace(const Key& key) {
1.1232 + typename Parent::Value& node = Parent::operator[](key);
1.1233 + typename std::map<Value, Key>::iterator it = _first.find(node.value);
1.1234 + if (it == _first.end()) {
1.1235 + node.prev = node.next = INVALID;
1.1236 + _first.insert(std::make_pair(node.value, key));
1.1237 + } else {
1.1238 + node.prev = INVALID;
1.1239 + node.next = it->second;
1.1240 + if (node.next != INVALID) {
1.1241 + Parent::operator[](node.next).prev = key;
1.1242 + }
1.1243 + it->second = key;
1.1244 + }
1.1245 + }
1.1246 +
1.1247 + public:
1.1248 +
1.1249 + /// \brief Forward iterator for values.
1.1250 + ///
1.1251 + /// This iterator is an STL compatible forward
1.1252 + /// iterator on the values of the map. The values can
1.1253 + /// be accessed in the <tt>[beginValue, endValue)</tt> range.
1.1254 + class ValueIt
1.1255 + : public std::iterator<std::forward_iterator_tag, Value> {
1.1256 + friend class IterableValueMap;
1.1257 + private:
1.1258 + ValueIt(typename std::map<Value, Key>::const_iterator _it)
1.1259 + : it(_it) {}
1.1260 + public:
1.1261 +
1.1262 + /// Constructor
1.1263 + ValueIt() {}
1.1264 +
1.1265 + /// \e
1.1266 + ValueIt& operator++() { ++it; return *this; }
1.1267 + /// \e
1.1268 + ValueIt operator++(int) {
1.1269 + ValueIt tmp(*this);
1.1270 + operator++();
1.1271 + return tmp;
1.1272 + }
1.1273 +
1.1274 + /// \e
1.1275 + const Value& operator*() const { return it->first; }
1.1276 + /// \e
1.1277 + const Value* operator->() const { return &(it->first); }
1.1278 +
1.1279 + /// \e
1.1280 + bool operator==(ValueIt jt) const { return it == jt.it; }
1.1281 + /// \e
1.1282 + bool operator!=(ValueIt jt) const { return it != jt.it; }
1.1283 +
1.1284 + private:
1.1285 + typename std::map<Value, Key>::const_iterator it;
1.1286 + };
1.1287 +
1.1288 + /// \brief Returns an iterator to the first value.
1.1289 + ///
1.1290 + /// Returns an STL compatible iterator to the
1.1291 + /// first value of the map. The values of the
1.1292 + /// map can be accessed in the <tt>[beginValue, endValue)</tt>
1.1293 + /// range.
1.1294 + ValueIt beginValue() const {
1.1295 + return ValueIt(_first.begin());
1.1296 + }
1.1297 +
1.1298 + /// \brief Returns an iterator after the last value.
1.1299 + ///
1.1300 + /// Returns an STL compatible iterator after the
1.1301 + /// last value of the map. The values of the
1.1302 + /// map can be accessed in the <tt>[beginValue, endValue)</tt>
1.1303 + /// range.
1.1304 + ValueIt endValue() const {
1.1305 + return ValueIt(_first.end());
1.1306 + }
1.1307 +
1.1308 + /// \brief Set operation of the map.
1.1309 + ///
1.1310 + /// Set operation of the map.
1.1311 + void set(const Key& key, const Value& value) {
1.1312 + unlace(key);
1.1313 + Parent::operator[](key).value = value;
1.1314 + lace(key);
1.1315 + }
1.1316 +
1.1317 + /// \brief Const subscript operator of the map.
1.1318 + ///
1.1319 + /// Const subscript operator of the map.
1.1320 + const Value& operator[](const Key& key) const {
1.1321 + return Parent::operator[](key).value;
1.1322 + }
1.1323 +
1.1324 + /// \brief Iterator for the keys with the same value.
1.1325 + ///
1.1326 + /// Iterator for the keys with the same value. It works
1.1327 + /// like a graph item iterator, it can be converted to
1.1328 + /// the item type of the map, incremented with \c ++ operator, and
1.1329 + /// if the iterator leaves the last valid item, it will be equal to
1.1330 + /// \c INVALID.
1.1331 + class ItemIt : public Key {
1.1332 + public:
1.1333 + typedef Key Parent;
1.1334 +
1.1335 + /// \brief Invalid constructor \& conversion.
1.1336 + ///
1.1337 + /// This constructor initializes the iterator to be invalid.
1.1338 + /// \sa Invalid for more details.
1.1339 + ItemIt(Invalid) : Parent(INVALID), _map(0) {}
1.1340 +
1.1341 + /// \brief Creates an iterator with a value.
1.1342 + ///
1.1343 + /// Creates an iterator with a value. It iterates on the
1.1344 + /// keys which have the given value.
1.1345 + /// \param map The IterableValueMap
1.1346 + /// \param value The value
1.1347 + ItemIt(const IterableValueMap& map, const Value& value) : _map(&map) {
1.1348 + typename std::map<Value, Key>::const_iterator it =
1.1349 + map._first.find(value);
1.1350 + if (it == map._first.end()) {
1.1351 + Parent::operator=(INVALID);
1.1352 + } else {
1.1353 + Parent::operator=(it->second);
1.1354 + }
1.1355 + }
1.1356 +
1.1357 + /// \brief Increment operator.
1.1358 + ///
1.1359 + /// Increment Operator.
1.1360 + ItemIt& operator++() {
1.1361 + Parent::operator=(_map->IterableValueMap::Parent::
1.1362 + operator[](static_cast<Parent&>(*this)).next);
1.1363 + return *this;
1.1364 + }
1.1365 +
1.1366 +
1.1367 + private:
1.1368 + const IterableValueMap* _map;
1.1369 + };
1.1370 +
1.1371 + protected:
1.1372 +
1.1373 + virtual void add(const Key& key) {
1.1374 + Parent::add(key);
1.1375 + unlace(key);
1.1376 + }
1.1377 +
1.1378 + virtual void add(const std::vector<Key>& keys) {
1.1379 + Parent::add(keys);
1.1380 + for (int i = 0; i < int(keys.size()); ++i) {
1.1381 + lace(keys[i]);
1.1382 + }
1.1383 + }
1.1384 +
1.1385 + virtual void erase(const Key& key) {
1.1386 + unlace(key);
1.1387 + Parent::erase(key);
1.1388 + }
1.1389 +
1.1390 + virtual void erase(const std::vector<Key>& keys) {
1.1391 + for (int i = 0; i < int(keys.size()); ++i) {
1.1392 + unlace(keys[i]);
1.1393 + }
1.1394 + Parent::erase(keys);
1.1395 + }
1.1396 +
1.1397 + virtual void build() {
1.1398 + Parent::build();
1.1399 + for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
1.1400 + lace(it);
1.1401 + }
1.1402 + }
1.1403 +
1.1404 + virtual void clear() {
1.1405 + _first.clear();
1.1406 + Parent::clear();
1.1407 + }
1.1408 +
1.1409 + private:
1.1410 + std::map<Value, Key> _first;
1.1411 + };
1.1412 +
1.1413 /// \brief Map of the source nodes of arcs in a digraph.
1.1414 ///
1.1415 /// SourceMap provides access for the source node of each arc in a digraph,
1.1416 @@ -2321,9 +3300,9 @@
1.1417 class SourceMap {
1.1418 public:
1.1419
1.1420 - ///\e
1.1421 + /// The key type (the \c Arc type of the digraph).
1.1422 typedef typename GR::Arc Key;
1.1423 - ///\e
1.1424 + /// The value type (the \c Node type of the digraph).
1.1425 typedef typename GR::Node Value;
1.1426
1.1427 /// \brief Constructor
1.1428 @@ -2362,9 +3341,9 @@
1.1429 class TargetMap {
1.1430 public:
1.1431
1.1432 - ///\e
1.1433 + /// The key type (the \c Arc type of the digraph).
1.1434 typedef typename GR::Arc Key;
1.1435 - ///\e
1.1436 + /// The value type (the \c Node type of the digraph).
1.1437 typedef typename GR::Node Value;
1.1438
1.1439 /// \brief Constructor
1.1440 @@ -2404,8 +3383,10 @@
1.1441 class ForwardMap {
1.1442 public:
1.1443
1.1444 + /// The key type (the \c Edge type of the digraph).
1.1445 + typedef typename GR::Edge Key;
1.1446 + /// The value type (the \c Arc type of the digraph).
1.1447 typedef typename GR::Arc Value;
1.1448 - typedef typename GR::Edge Key;
1.1449
1.1450 /// \brief Constructor
1.1451 ///
1.1452 @@ -2444,8 +3425,10 @@
1.1453 class BackwardMap {
1.1454 public:
1.1455
1.1456 + /// The key type (the \c Edge type of the digraph).
1.1457 + typedef typename GR::Edge Key;
1.1458 + /// The value type (the \c Arc type of the digraph).
1.1459 typedef typename GR::Arc Value;
1.1460 - typedef typename GR::Edge Key;
1.1461
1.1462 /// \brief Constructor
1.1463 ///
1.1464 @@ -2480,10 +3463,10 @@
1.1465 /// in constant time. On the other hand, the values are updated automatically
1.1466 /// whenever the digraph changes.
1.1467 ///
1.1468 - /// \warning Besides \c addNode() and \c addArc(), a digraph structure
1.1469 + /// \warning Besides \c addNode() and \c addArc(), a digraph structure
1.1470 /// may provide alternative ways to modify the digraph.
1.1471 /// The correct behavior of InDegMap is not guarantied if these additional
1.1472 - /// features are used. For example the functions
1.1473 + /// features are used. For example, the functions
1.1474 /// \ref ListDigraph::changeSource() "changeSource()",
1.1475 /// \ref ListDigraph::changeTarget() "changeTarget()" and
1.1476 /// \ref ListDigraph::reverseArc() "reverseArc()"
1.1477 @@ -2496,7 +3479,7 @@
1.1478 ::ItemNotifier::ObserverBase {
1.1479
1.1480 public:
1.1481 -
1.1482 +
1.1483 /// The graph type of InDegMap
1.1484 typedef GR Graph;
1.1485 typedef GR Digraph;
1.1486 @@ -2610,10 +3593,10 @@
1.1487 /// in constant time. On the other hand, the values are updated automatically
1.1488 /// whenever the digraph changes.
1.1489 ///
1.1490 - /// \warning Besides \c addNode() and \c addArc(), a digraph structure
1.1491 + /// \warning Besides \c addNode() and \c addArc(), a digraph structure
1.1492 /// may provide alternative ways to modify the digraph.
1.1493 /// The correct behavior of OutDegMap is not guarantied if these additional
1.1494 - /// features are used. For example the functions
1.1495 + /// features are used. For example, the functions
1.1496 /// \ref ListDigraph::changeSource() "changeSource()",
1.1497 /// \ref ListDigraph::changeTarget() "changeTarget()" and
1.1498 /// \ref ListDigraph::reverseArc() "reverseArc()"
1.1499 @@ -2781,6 +3764,293 @@
1.1500 return PotentialDifferenceMap<GR, POT>(gr, potential);
1.1501 }
1.1502
1.1503 +
1.1504 + /// \brief Copy the values of a graph map to another map.
1.1505 + ///
1.1506 + /// This function copies the values of a graph map to another graph map.
1.1507 + /// \c To::Key must be equal or convertible to \c From::Key and
1.1508 + /// \c From::Value must be equal or convertible to \c To::Value.
1.1509 + ///
1.1510 + /// For example, an edge map of \c int value type can be copied to
1.1511 + /// an arc map of \c double value type in an undirected graph, but
1.1512 + /// an arc map cannot be copied to an edge map.
1.1513 + /// Note that even a \ref ConstMap can be copied to a standard graph map,
1.1514 + /// but \ref mapFill() can also be used for this purpose.
1.1515 + ///
1.1516 + /// \param gr The graph for which the maps are defined.
1.1517 + /// \param from The map from which the values have to be copied.
1.1518 + /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
1.1519 + /// \param to The map to which the values have to be copied.
1.1520 + /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
1.1521 + template <typename GR, typename From, typename To>
1.1522 + void mapCopy(const GR& gr, const From& from, To& to) {
1.1523 + typedef typename To::Key Item;
1.1524 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
1.1525 +
1.1526 + for (ItemIt it(gr); it != INVALID; ++it) {
1.1527 + to.set(it, from[it]);
1.1528 + }
1.1529 + }
1.1530 +
1.1531 + /// \brief Compare two graph maps.
1.1532 + ///
1.1533 + /// This function compares the values of two graph maps. It returns
1.1534 + /// \c true if the maps assign the same value for all items in the graph.
1.1535 + /// The \c Key type of the maps (\c Node, \c Arc or \c Edge) must be equal
1.1536 + /// and their \c Value types must be comparable using \c %operator==().
1.1537 + ///
1.1538 + /// \param gr The graph for which the maps are defined.
1.1539 + /// \param map1 The first map.
1.1540 + /// \param map2 The second map.
1.1541 + template <typename GR, typename Map1, typename Map2>
1.1542 + bool mapCompare(const GR& gr, const Map1& map1, const Map2& map2) {
1.1543 + typedef typename Map2::Key Item;
1.1544 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
1.1545 +
1.1546 + for (ItemIt it(gr); it != INVALID; ++it) {
1.1547 + if (!(map1[it] == map2[it])) return false;
1.1548 + }
1.1549 + return true;
1.1550 + }
1.1551 +
1.1552 + /// \brief Return an item having minimum value of a graph map.
1.1553 + ///
1.1554 + /// This function returns an item (\c Node, \c Arc or \c Edge) having
1.1555 + /// minimum value of the given graph map.
1.1556 + /// If the item set is empty, it returns \c INVALID.
1.1557 + ///
1.1558 + /// \param gr The graph for which the map is defined.
1.1559 + /// \param map The graph map.
1.1560 + template <typename GR, typename Map>
1.1561 + typename Map::Key mapMin(const GR& gr, const Map& map) {
1.1562 + return mapMin(gr, map, std::less<typename Map::Value>());
1.1563 + }
1.1564 +
1.1565 + /// \brief Return an item having minimum value of a graph map.
1.1566 + ///
1.1567 + /// This function returns an item (\c Node, \c Arc or \c Edge) having
1.1568 + /// minimum value of the given graph map.
1.1569 + /// If the item set is empty, it returns \c INVALID.
1.1570 + ///
1.1571 + /// \param gr The graph for which the map is defined.
1.1572 + /// \param map The graph map.
1.1573 + /// \param comp Comparison function object.
1.1574 + template <typename GR, typename Map, typename Comp>
1.1575 + typename Map::Key mapMin(const GR& gr, const Map& map, const Comp& comp) {
1.1576 + typedef typename Map::Key Item;
1.1577 + typedef typename Map::Value Value;
1.1578 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
1.1579 +
1.1580 + ItemIt min_item(gr);
1.1581 + if (min_item == INVALID) return INVALID;
1.1582 + Value min = map[min_item];
1.1583 + for (ItemIt it(gr); it != INVALID; ++it) {
1.1584 + if (comp(map[it], min)) {
1.1585 + min = map[it];
1.1586 + min_item = it;
1.1587 + }
1.1588 + }
1.1589 + return min_item;
1.1590 + }
1.1591 +
1.1592 + /// \brief Return an item having maximum value of a graph map.
1.1593 + ///
1.1594 + /// This function returns an item (\c Node, \c Arc or \c Edge) having
1.1595 + /// maximum value of the given graph map.
1.1596 + /// If the item set is empty, it returns \c INVALID.
1.1597 + ///
1.1598 + /// \param gr The graph for which the map is defined.
1.1599 + /// \param map The graph map.
1.1600 + template <typename GR, typename Map>
1.1601 + typename Map::Key mapMax(const GR& gr, const Map& map) {
1.1602 + return mapMax(gr, map, std::less<typename Map::Value>());
1.1603 + }
1.1604 +
1.1605 + /// \brief Return an item having maximum value of a graph map.
1.1606 + ///
1.1607 + /// This function returns an item (\c Node, \c Arc or \c Edge) having
1.1608 + /// maximum value of the given graph map.
1.1609 + /// If the item set is empty, it returns \c INVALID.
1.1610 + ///
1.1611 + /// \param gr The graph for which the map is defined.
1.1612 + /// \param map The graph map.
1.1613 + /// \param comp Comparison function object.
1.1614 + template <typename GR, typename Map, typename Comp>
1.1615 + typename Map::Key mapMax(const GR& gr, const Map& map, const Comp& comp) {
1.1616 + typedef typename Map::Key Item;
1.1617 + typedef typename Map::Value Value;
1.1618 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
1.1619 +
1.1620 + ItemIt max_item(gr);
1.1621 + if (max_item == INVALID) return INVALID;
1.1622 + Value max = map[max_item];
1.1623 + for (ItemIt it(gr); it != INVALID; ++it) {
1.1624 + if (comp(max, map[it])) {
1.1625 + max = map[it];
1.1626 + max_item = it;
1.1627 + }
1.1628 + }
1.1629 + return max_item;
1.1630 + }
1.1631 +
1.1632 + /// \brief Return the minimum value of a graph map.
1.1633 + ///
1.1634 + /// This function returns the minimum value of the given graph map.
1.1635 + /// The corresponding item set of the graph must not be empty.
1.1636 + ///
1.1637 + /// \param gr The graph for which the map is defined.
1.1638 + /// \param map The graph map.
1.1639 + template <typename GR, typename Map>
1.1640 + typename Map::Value mapMinValue(const GR& gr, const Map& map) {
1.1641 + return map[mapMin(gr, map, std::less<typename Map::Value>())];
1.1642 + }
1.1643 +
1.1644 + /// \brief Return the minimum value of a graph map.
1.1645 + ///
1.1646 + /// This function returns the minimum value of the given graph map.
1.1647 + /// The corresponding item set of the graph must not be empty.
1.1648 + ///
1.1649 + /// \param gr The graph for which the map is defined.
1.1650 + /// \param map The graph map.
1.1651 + /// \param comp Comparison function object.
1.1652 + template <typename GR, typename Map, typename Comp>
1.1653 + typename Map::Value
1.1654 + mapMinValue(const GR& gr, const Map& map, const Comp& comp) {
1.1655 + return map[mapMin(gr, map, comp)];
1.1656 + }
1.1657 +
1.1658 + /// \brief Return the maximum value of a graph map.
1.1659 + ///
1.1660 + /// This function returns the maximum value of the given graph map.
1.1661 + /// The corresponding item set of the graph must not be empty.
1.1662 + ///
1.1663 + /// \param gr The graph for which the map is defined.
1.1664 + /// \param map The graph map.
1.1665 + template <typename GR, typename Map>
1.1666 + typename Map::Value mapMaxValue(const GR& gr, const Map& map) {
1.1667 + return map[mapMax(gr, map, std::less<typename Map::Value>())];
1.1668 + }
1.1669 +
1.1670 + /// \brief Return the maximum value of a graph map.
1.1671 + ///
1.1672 + /// This function returns the maximum value of the given graph map.
1.1673 + /// The corresponding item set of the graph must not be empty.
1.1674 + ///
1.1675 + /// \param gr The graph for which the map is defined.
1.1676 + /// \param map The graph map.
1.1677 + /// \param comp Comparison function object.
1.1678 + template <typename GR, typename Map, typename Comp>
1.1679 + typename Map::Value
1.1680 + mapMaxValue(const GR& gr, const Map& map, const Comp& comp) {
1.1681 + return map[mapMax(gr, map, comp)];
1.1682 + }
1.1683 +
1.1684 + /// \brief Return an item having a specified value in a graph map.
1.1685 + ///
1.1686 + /// This function returns an item (\c Node, \c Arc or \c Edge) having
1.1687 + /// the specified assigned value in the given graph map.
1.1688 + /// If no such item exists, it returns \c INVALID.
1.1689 + ///
1.1690 + /// \param gr The graph for which the map is defined.
1.1691 + /// \param map The graph map.
1.1692 + /// \param val The value that have to be found.
1.1693 + template <typename GR, typename Map>
1.1694 + typename Map::Key
1.1695 + mapFind(const GR& gr, const Map& map, const typename Map::Value& val) {
1.1696 + typedef typename Map::Key Item;
1.1697 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
1.1698 +
1.1699 + for (ItemIt it(gr); it != INVALID; ++it) {
1.1700 + if (map[it] == val) return it;
1.1701 + }
1.1702 + return INVALID;
1.1703 + }
1.1704 +
1.1705 + /// \brief Return an item having value for which a certain predicate is
1.1706 + /// true in a graph map.
1.1707 + ///
1.1708 + /// This function returns an item (\c Node, \c Arc or \c Edge) having
1.1709 + /// such assigned value for which the specified predicate is true
1.1710 + /// in the given graph map.
1.1711 + /// If no such item exists, it returns \c INVALID.
1.1712 + ///
1.1713 + /// \param gr The graph for which the map is defined.
1.1714 + /// \param map The graph map.
1.1715 + /// \param pred The predicate function object.
1.1716 + template <typename GR, typename Map, typename Pred>
1.1717 + typename Map::Key
1.1718 + mapFindIf(const GR& gr, const Map& map, const Pred& pred) {
1.1719 + typedef typename Map::Key Item;
1.1720 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
1.1721 +
1.1722 + for (ItemIt it(gr); it != INVALID; ++it) {
1.1723 + if (pred(map[it])) return it;
1.1724 + }
1.1725 + return INVALID;
1.1726 + }
1.1727 +
1.1728 + /// \brief Return the number of items having a specified value in a
1.1729 + /// graph map.
1.1730 + ///
1.1731 + /// This function returns the number of items (\c Node, \c Arc or \c Edge)
1.1732 + /// having the specified assigned value in the given graph map.
1.1733 + ///
1.1734 + /// \param gr The graph for which the map is defined.
1.1735 + /// \param map The graph map.
1.1736 + /// \param val The value that have to be counted.
1.1737 + template <typename GR, typename Map>
1.1738 + int mapCount(const GR& gr, const Map& map, const typename Map::Value& val) {
1.1739 + typedef typename Map::Key Item;
1.1740 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
1.1741 +
1.1742 + int cnt = 0;
1.1743 + for (ItemIt it(gr); it != INVALID; ++it) {
1.1744 + if (map[it] == val) ++cnt;
1.1745 + }
1.1746 + return cnt;
1.1747 + }
1.1748 +
1.1749 + /// \brief Return the number of items having values for which a certain
1.1750 + /// predicate is true in a graph map.
1.1751 + ///
1.1752 + /// This function returns the number of items (\c Node, \c Arc or \c Edge)
1.1753 + /// having such assigned values for which the specified predicate is true
1.1754 + /// in the given graph map.
1.1755 + ///
1.1756 + /// \param gr The graph for which the map is defined.
1.1757 + /// \param map The graph map.
1.1758 + /// \param pred The predicate function object.
1.1759 + template <typename GR, typename Map, typename Pred>
1.1760 + int mapCountIf(const GR& gr, const Map& map, const Pred& pred) {
1.1761 + typedef typename Map::Key Item;
1.1762 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
1.1763 +
1.1764 + int cnt = 0;
1.1765 + for (ItemIt it(gr); it != INVALID; ++it) {
1.1766 + if (pred(map[it])) ++cnt;
1.1767 + }
1.1768 + return cnt;
1.1769 + }
1.1770 +
1.1771 + /// \brief Fill a graph map with a certain value.
1.1772 + ///
1.1773 + /// This function sets the specified value for all items (\c Node,
1.1774 + /// \c Arc or \c Edge) in the given graph map.
1.1775 + ///
1.1776 + /// \param gr The graph for which the map is defined.
1.1777 + /// \param map The graph map. It must conform to the
1.1778 + /// \ref concepts::WriteMap "WriteMap" concept.
1.1779 + /// \param val The value.
1.1780 + template <typename GR, typename Map>
1.1781 + void mapFill(const GR& gr, Map& map, const typename Map::Value& val) {
1.1782 + typedef typename Map::Key Item;
1.1783 + typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
1.1784 +
1.1785 + for (ItemIt it(gr); it != INVALID; ++it) {
1.1786 + map.set(it, val);
1.1787 + }
1.1788 + }
1.1789 +
1.1790 /// @}
1.1791 }
1.1792