Map utility functions (#320)
authorPeter Kovacs <kpeter@inf.elte.hu>
Fri, 13 Nov 2009 12:47:13 +0100
changeset 7898ddb7deabab9
parent 784 1a7fe3bef514
child 791 4e3484a2e90c
Map utility functions (#320)
lemon/maps.h
test/maps_test.cc
     1.1 --- a/lemon/maps.h	Thu Nov 05 15:50:01 2009 +0100
     1.2 +++ b/lemon/maps.h	Fri Nov 13 12:47:13 2009 +0100
     1.3 @@ -3764,6 +3764,293 @@
     1.4      return PotentialDifferenceMap<GR, POT>(gr, potential);
     1.5    }
     1.6  
     1.7 +
     1.8 +  /// \brief Copy the values of a graph map to another map.
     1.9 +  ///
    1.10 +  /// This function copies the values of a graph map to another graph map.
    1.11 +  /// \c To::Key must be equal or convertible to \c From::Key and
    1.12 +  /// \c From::Value must be equal or convertible to \c To::Value.
    1.13 +  ///
    1.14 +  /// For example, an edge map of \c int value type can be copied to
    1.15 +  /// an arc map of \c double value type in an undirected graph, but
    1.16 +  /// an arc map cannot be copied to an edge map.
    1.17 +  /// Note that even a \ref ConstMap can be copied to a standard graph map,
    1.18 +  /// but \ref mapFill() can also be used for this purpose.
    1.19 +  ///
    1.20 +  /// \param gr The graph for which the maps are defined.
    1.21 +  /// \param from The map from which the values have to be copied.
    1.22 +  /// It must conform to the \ref concepts::ReadMap "ReadMap" concept.
    1.23 +  /// \param to The map to which the values have to be copied.
    1.24 +  /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
    1.25 +  template <typename GR, typename From, typename To>
    1.26 +  void mapCopy(const GR& gr, const From& from, To& to) {
    1.27 +    typedef typename To::Key Item;
    1.28 +    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
    1.29 +    
    1.30 +    for (ItemIt it(gr); it != INVALID; ++it) {
    1.31 +      to.set(it, from[it]);
    1.32 +    }
    1.33 +  }
    1.34 +
    1.35 +  /// \brief Compare two graph maps.
    1.36 +  ///
    1.37 +  /// This function compares the values of two graph maps. It returns 
    1.38 +  /// \c true if the maps assign the same value for all items in the graph.
    1.39 +  /// The \c Key type of the maps (\c Node, \c Arc or \c Edge) must be equal
    1.40 +  /// and their \c Value types must be comparable using \c %operator==().
    1.41 +  ///
    1.42 +  /// \param gr The graph for which the maps are defined.
    1.43 +  /// \param map1 The first map.
    1.44 +  /// \param map2 The second map.
    1.45 +  template <typename GR, typename Map1, typename Map2>
    1.46 +  bool mapCompare(const GR& gr, const Map1& map1, const Map2& map2) {
    1.47 +    typedef typename Map2::Key Item;
    1.48 +    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
    1.49 +    
    1.50 +    for (ItemIt it(gr); it != INVALID; ++it) {
    1.51 +      if (!(map1[it] == map2[it])) return false;
    1.52 +    }
    1.53 +    return true;
    1.54 +  }
    1.55 +
    1.56 +  /// \brief Return an item having minimum value of a graph map.
    1.57 +  ///
    1.58 +  /// This function returns an item (\c Node, \c Arc or \c Edge) having
    1.59 +  /// minimum value of the given graph map.
    1.60 +  /// If the item set is empty, it returns \c INVALID.
    1.61 +  ///
    1.62 +  /// \param gr The graph for which the map is defined.
    1.63 +  /// \param map The graph map.
    1.64 +  template <typename GR, typename Map>
    1.65 +  typename Map::Key mapMin(const GR& gr, const Map& map) {
    1.66 +    return mapMin(gr, map, std::less<typename Map::Value>());
    1.67 +  }
    1.68 +
    1.69 +  /// \brief Return an item having minimum value of a graph map.
    1.70 +  ///
    1.71 +  /// This function returns an item (\c Node, \c Arc or \c Edge) having
    1.72 +  /// minimum value of the given graph map.
    1.73 +  /// If the item set is empty, it returns \c INVALID.
    1.74 +  ///
    1.75 +  /// \param gr The graph for which the map is defined.
    1.76 +  /// \param map The graph map.
    1.77 +  /// \param comp Comparison function object.
    1.78 +  template <typename GR, typename Map, typename Comp>
    1.79 +  typename Map::Key mapMin(const GR& gr, const Map& map, const Comp& comp) {
    1.80 +    typedef typename Map::Key Item;
    1.81 +    typedef typename Map::Value Value;
    1.82 +    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
    1.83 +
    1.84 +    ItemIt min_item(gr);
    1.85 +    if (min_item == INVALID) return INVALID;
    1.86 +    Value min = map[min_item];
    1.87 +    for (ItemIt it(gr); it != INVALID; ++it) {
    1.88 +      if (comp(map[it], min)) {
    1.89 +        min = map[it];
    1.90 +        min_item = it;
    1.91 +      }
    1.92 +    }
    1.93 +    return min_item;
    1.94 +  }
    1.95 +
    1.96 +  /// \brief Return an item having maximum value of a graph map.
    1.97 +  ///
    1.98 +  /// This function returns an item (\c Node, \c Arc or \c Edge) having
    1.99 +  /// maximum value of the given graph map.
   1.100 +  /// If the item set is empty, it returns \c INVALID.
   1.101 +  ///
   1.102 +  /// \param gr The graph for which the map is defined.
   1.103 +  /// \param map The graph map.
   1.104 +  template <typename GR, typename Map>
   1.105 +  typename Map::Key mapMax(const GR& gr, const Map& map) {
   1.106 +    return mapMax(gr, map, std::less<typename Map::Value>());
   1.107 +  }
   1.108 +
   1.109 +  /// \brief Return an item having maximum value of a graph map.
   1.110 +  ///
   1.111 +  /// This function returns an item (\c Node, \c Arc or \c Edge) having
   1.112 +  /// maximum value of the given graph map.
   1.113 +  /// If the item set is empty, it returns \c INVALID.
   1.114 +  ///
   1.115 +  /// \param gr The graph for which the map is defined.
   1.116 +  /// \param map The graph map.
   1.117 +  /// \param comp Comparison function object.
   1.118 +  template <typename GR, typename Map, typename Comp>
   1.119 +  typename Map::Key mapMax(const GR& gr, const Map& map, const Comp& comp) {
   1.120 +    typedef typename Map::Key Item;
   1.121 +    typedef typename Map::Value Value;
   1.122 +    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
   1.123 +
   1.124 +    ItemIt max_item(gr);
   1.125 +    if (max_item == INVALID) return INVALID;
   1.126 +    Value max = map[max_item];
   1.127 +    for (ItemIt it(gr); it != INVALID; ++it) {
   1.128 +      if (comp(max, map[it])) {
   1.129 +        max = map[it];
   1.130 +        max_item = it;
   1.131 +      }
   1.132 +    }
   1.133 +    return max_item;
   1.134 +  }
   1.135 +
   1.136 +  /// \brief Return the minimum value of a graph map.
   1.137 +  ///
   1.138 +  /// This function returns the minimum value of the given graph map.
   1.139 +  /// The corresponding item set of the graph must not be empty.
   1.140 +  ///
   1.141 +  /// \param gr The graph for which the map is defined.
   1.142 +  /// \param map The graph map.
   1.143 +  template <typename GR, typename Map>
   1.144 +  typename Map::Value mapMinValue(const GR& gr, const Map& map) {
   1.145 +    return map[mapMin(gr, map, std::less<typename Map::Value>())];
   1.146 +  }
   1.147 +
   1.148 +  /// \brief Return the minimum value of a graph map.
   1.149 +  ///
   1.150 +  /// This function returns the minimum value of the given graph map.
   1.151 +  /// The corresponding item set of the graph must not be empty.
   1.152 +  ///
   1.153 +  /// \param gr The graph for which the map is defined.
   1.154 +  /// \param map The graph map.
   1.155 +  /// \param comp Comparison function object.
   1.156 +  template <typename GR, typename Map, typename Comp>
   1.157 +  typename Map::Value
   1.158 +  mapMinValue(const GR& gr, const Map& map, const Comp& comp) {
   1.159 +    return map[mapMin(gr, map, comp)];
   1.160 +  }
   1.161 +
   1.162 +  /// \brief Return the maximum value of a graph map.
   1.163 +  ///
   1.164 +  /// This function returns the maximum value of the given graph map.
   1.165 +  /// The corresponding item set of the graph must not be empty.
   1.166 +  ///
   1.167 +  /// \param gr The graph for which the map is defined.
   1.168 +  /// \param map The graph map.
   1.169 +  template <typename GR, typename Map>
   1.170 +  typename Map::Value mapMaxValue(const GR& gr, const Map& map) {
   1.171 +    return map[mapMax(gr, map, std::less<typename Map::Value>())];
   1.172 +  }
   1.173 +
   1.174 +  /// \brief Return the maximum value of a graph map.
   1.175 +  ///
   1.176 +  /// This function returns the maximum value of the given graph map.
   1.177 +  /// The corresponding item set of the graph must not be empty.
   1.178 +  ///
   1.179 +  /// \param gr The graph for which the map is defined.
   1.180 +  /// \param map The graph map.
   1.181 +  /// \param comp Comparison function object.
   1.182 +  template <typename GR, typename Map, typename Comp>
   1.183 +  typename Map::Value
   1.184 +  mapMaxValue(const GR& gr, const Map& map, const Comp& comp) {
   1.185 +    return map[mapMax(gr, map, comp)];
   1.186 +  }
   1.187 +
   1.188 +  /// \brief Return an item having a specified value in a graph map.
   1.189 +  ///
   1.190 +  /// This function returns an item (\c Node, \c Arc or \c Edge) having
   1.191 +  /// the specified assigned value in the given graph map.
   1.192 +  /// If no such item exists, it returns \c INVALID.
   1.193 +  ///
   1.194 +  /// \param gr The graph for which the map is defined.
   1.195 +  /// \param map The graph map.
   1.196 +  /// \param val The value that have to be found.
   1.197 +  template <typename GR, typename Map>
   1.198 +  typename Map::Key
   1.199 +  mapFind(const GR& gr, const Map& map, const typename Map::Value& val) {
   1.200 +    typedef typename Map::Key Item;
   1.201 +    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
   1.202 +
   1.203 +    for (ItemIt it(gr); it != INVALID; ++it) {
   1.204 +      if (map[it] == val) return it;
   1.205 +    }
   1.206 +    return INVALID;
   1.207 +  }
   1.208 +
   1.209 +  /// \brief Return an item having value for which a certain predicate is
   1.210 +  /// true in a graph map.
   1.211 +  ///
   1.212 +  /// This function returns an item (\c Node, \c Arc or \c Edge) having
   1.213 +  /// such assigned value for which the specified predicate is true
   1.214 +  /// in the given graph map.
   1.215 +  /// If no such item exists, it returns \c INVALID.
   1.216 +  ///
   1.217 +  /// \param gr The graph for which the map is defined.
   1.218 +  /// \param map The graph map.
   1.219 +  /// \param pred The predicate function object.
   1.220 +  template <typename GR, typename Map, typename Pred>
   1.221 +  typename Map::Key
   1.222 +  mapFindIf(const GR& gr, const Map& map, const Pred& pred) {
   1.223 +    typedef typename Map::Key Item;
   1.224 +    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
   1.225 +
   1.226 +    for (ItemIt it(gr); it != INVALID; ++it) {
   1.227 +      if (pred(map[it])) return it;
   1.228 +    }
   1.229 +    return INVALID;
   1.230 +  }
   1.231 +
   1.232 +  /// \brief Return the number of items having a specified value in a
   1.233 +  /// graph map.
   1.234 +  ///
   1.235 +  /// This function returns the number of items (\c Node, \c Arc or \c Edge)
   1.236 +  /// having the specified assigned value in the given graph map.
   1.237 +  ///
   1.238 +  /// \param gr The graph for which the map is defined.
   1.239 +  /// \param map The graph map.
   1.240 +  /// \param val The value that have to be counted.
   1.241 +  template <typename GR, typename Map>
   1.242 +  int mapCount(const GR& gr, const Map& map, const typename Map::Value& val) {
   1.243 +    typedef typename Map::Key Item;
   1.244 +    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
   1.245 +
   1.246 +    int cnt = 0;
   1.247 +    for (ItemIt it(gr); it != INVALID; ++it) {
   1.248 +      if (map[it] == val) ++cnt;
   1.249 +    }
   1.250 +    return cnt;
   1.251 +  }
   1.252 +
   1.253 +  /// \brief Return the number of items having values for which a certain
   1.254 +  /// predicate is true in a graph map.
   1.255 +  ///
   1.256 +  /// This function returns the number of items (\c Node, \c Arc or \c Edge)
   1.257 +  /// having such assigned values for which the specified predicate is true
   1.258 +  /// in the given graph map.
   1.259 +  ///
   1.260 +  /// \param gr The graph for which the map is defined.
   1.261 +  /// \param map The graph map.
   1.262 +  /// \param pred The predicate function object.
   1.263 +  template <typename GR, typename Map, typename Pred>
   1.264 +  int mapCountIf(const GR& gr, const Map& map, const Pred& pred) {
   1.265 +    typedef typename Map::Key Item;
   1.266 +    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
   1.267 +
   1.268 +    int cnt = 0;
   1.269 +    for (ItemIt it(gr); it != INVALID; ++it) {
   1.270 +      if (pred(map[it])) ++cnt;
   1.271 +    }
   1.272 +    return cnt;
   1.273 +  }
   1.274 +
   1.275 +  /// \brief Fill a graph map with a certain value.
   1.276 +  ///
   1.277 +  /// This function sets the specified value for all items (\c Node,
   1.278 +  /// \c Arc or \c Edge) in the given graph map.
   1.279 +  ///
   1.280 +  /// \param gr The graph for which the map is defined.
   1.281 +  /// \param map The graph map. It must conform to the
   1.282 +  /// \ref concepts::WriteMap "WriteMap" concept.
   1.283 +  /// \param val The value.
   1.284 +  template <typename GR, typename Map>
   1.285 +  void mapFill(const GR& gr, Map& map, const typename Map::Value& val) {
   1.286 +    typedef typename Map::Key Item;
   1.287 +    typedef typename ItemSetTraits<GR, Item>::ItemIt ItemIt;
   1.288 +
   1.289 +    for (ItemIt it(gr); it != INVALID; ++it) {
   1.290 +      map.set(it, val);
   1.291 +    }
   1.292 +  }
   1.293 +
   1.294    /// @}
   1.295  }
   1.296  
     2.1 --- a/test/maps_test.cc	Thu Nov 05 15:50:01 2009 +0100
     2.2 +++ b/test/maps_test.cc	Fri Nov 13 12:47:13 2009 +0100
     2.3 @@ -26,6 +26,7 @@
     2.4  #include <lemon/smart_graph.h>
     2.5  #include <lemon/adaptors.h>
     2.6  #include <lemon/dfs.h>
     2.7 +#include <algorithm>
     2.8  
     2.9  #include "test_tools.h"
    2.10  
    2.11 @@ -37,9 +38,22 @@
    2.12  struct B {};
    2.13  
    2.14  class C {
    2.15 -  int x;
    2.16 +  int _x;
    2.17  public:
    2.18 -  C(int _x) : x(_x) {}
    2.19 +  C(int x) : _x(x) {}
    2.20 +  int get() const { return _x; }
    2.21 +};
    2.22 +inline bool operator<(C c1, C c2) { return c1.get() < c2.get(); }
    2.23 +inline bool operator==(C c1, C c2) { return c1.get() == c2.get(); }
    2.24 +
    2.25 +C createC(int x) { return C(x); }
    2.26 +
    2.27 +template <typename T>
    2.28 +class Less {
    2.29 +  T _t;
    2.30 +public:
    2.31 +  Less(T t): _t(t) {}
    2.32 +  bool operator()(const T& t) const { return t < _t; }
    2.33  };
    2.34  
    2.35  class F {
    2.36 @@ -56,6 +70,14 @@
    2.37  
    2.38  int binc(int a, B) { return a+1; }
    2.39  
    2.40 +template <typename T>
    2.41 +class Sum {
    2.42 +  T& _sum;
    2.43 +public:
    2.44 +  Sum(T& sum) : _sum(sum) {}
    2.45 +  void operator()(const T& t) { _sum += t; }
    2.46 +};
    2.47 +
    2.48  typedef ReadMap<A, double> DoubleMap;
    2.49  typedef ReadWriteMap<A, double> DoubleWriteMap;
    2.50  typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
    2.51 @@ -64,12 +86,6 @@
    2.52  typedef ReadWriteMap<A, bool> BoolWriteMap;
    2.53  typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
    2.54  
    2.55 -template<typename Map1, typename Map2, typename ItemIt>
    2.56 -void compareMap(const Map1& map1, const Map2& map2, ItemIt it) {
    2.57 -  for (; it != INVALID; ++it)
    2.58 -    check(map1[it] == map2[it], "The maps are not equal");
    2.59 -}
    2.60 -
    2.61  int main()
    2.62  {
    2.63    // Map concepts
    2.64 @@ -494,9 +510,10 @@
    2.65        check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
    2.66      }
    2.67      
    2.68 -    compareMap(sourceMap(orienter(gr, constMap<Edge, bool>(true))),
    2.69 -               targetMap(orienter(gr, constMap<Edge, bool>(false))),
    2.70 -               EdgeIt(gr));
    2.71 +    check(mapCompare(gr,
    2.72 +          sourceMap(orienter(gr, constMap<Edge, bool>(true))),
    2.73 +          targetMap(orienter(gr, constMap<Edge, bool>(false)))),
    2.74 +          "Wrong SourceMap or TargetMap");
    2.75  
    2.76      typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
    2.77      Digraph dgr(gr, constMap<Edge, bool>(true));
    2.78 @@ -800,5 +817,183 @@
    2.79      check(n == num, "Wrong number");
    2.80  
    2.81    }
    2.82 +  
    2.83 +  // Graph map utilities:
    2.84 +  // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
    2.85 +  // mapFind(), mapFindIf(), mapCount(), mapCountIf()
    2.86 +  // mapCopy(), mapCompare(), mapFill()
    2.87 +  {
    2.88 +    DIGRAPH_TYPEDEFS(SmartDigraph);
    2.89 +
    2.90 +    SmartDigraph g;
    2.91 +    Node n1 = g.addNode();
    2.92 +    Node n2 = g.addNode();
    2.93 +    Node n3 = g.addNode();
    2.94 +    
    2.95 +    SmartDigraph::NodeMap<int> map1(g);
    2.96 +    SmartDigraph::ArcMap<char> map2(g);
    2.97 +    ConstMap<Node, A> cmap1 = A();
    2.98 +    ConstMap<Arc, C> cmap2 = C(0);
    2.99 +    
   2.100 +    map1[n1] = 10;
   2.101 +    map1[n2] = 5;
   2.102 +    map1[n3] = 12;
   2.103 +    
   2.104 +    // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
   2.105 +    check(mapMin(g, map1) == n2, "Wrong mapMin()");
   2.106 +    check(mapMax(g, map1) == n3, "Wrong mapMax()");
   2.107 +    check(mapMin(g, map1, std::greater<int>()) == n3, "Wrong mapMin()");
   2.108 +    check(mapMax(g, map1, std::greater<int>()) == n2, "Wrong mapMax()");
   2.109 +    check(mapMinValue(g, map1) == 5, "Wrong mapMinValue()");
   2.110 +    check(mapMaxValue(g, map1) == 12, "Wrong mapMaxValue()");
   2.111 +
   2.112 +    check(mapMin(g, map2) == INVALID, "Wrong mapMin()");
   2.113 +    check(mapMax(g, map2) == INVALID, "Wrong mapMax()");
   2.114 +
   2.115 +    check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
   2.116 +    check(mapMax(g, cmap2) == INVALID, "Wrong mapMax()");
   2.117 +
   2.118 +    Arc a1 = g.addArc(n1, n2);
   2.119 +    Arc a2 = g.addArc(n1, n3);
   2.120 +    Arc a3 = g.addArc(n2, n3);
   2.121 +    Arc a4 = g.addArc(n3, n1);
   2.122 +    
   2.123 +    map2[a1] = 'b';
   2.124 +    map2[a2] = 'a';
   2.125 +    map2[a3] = 'b';
   2.126 +    map2[a4] = 'c';
   2.127 +
   2.128 +    // mapMin(), mapMax(), mapMinValue(), mapMaxValue()
   2.129 +    check(mapMin(g, map2) == a2, "Wrong mapMin()");
   2.130 +    check(mapMax(g, map2) == a4, "Wrong mapMax()");
   2.131 +    check(mapMin(g, map2, std::greater<int>()) == a4, "Wrong mapMin()");
   2.132 +    check(mapMax(g, map2, std::greater<int>()) == a2, "Wrong mapMax()");
   2.133 +    check(mapMinValue(g, map2, std::greater<int>()) == 'c',
   2.134 +          "Wrong mapMinValue()");
   2.135 +    check(mapMaxValue(g, map2, std::greater<int>()) == 'a',
   2.136 +          "Wrong mapMaxValue()");
   2.137 +
   2.138 +    check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
   2.139 +    check(mapMax(g, cmap2) != INVALID, "Wrong mapMax()");
   2.140 +    check(mapMaxValue(g, cmap2) == C(0), "Wrong mapMaxValue()");
   2.141 +
   2.142 +    check(mapMin(g, composeMap(functorToMap(&createC), map2)) == a2,
   2.143 +          "Wrong mapMin()");
   2.144 +    check(mapMax(g, composeMap(functorToMap(&createC), map2)) == a4,
   2.145 +          "Wrong mapMax()");
   2.146 +    check(mapMinValue(g, composeMap(functorToMap(&createC), map2)) == C('a'),
   2.147 +          "Wrong mapMinValue()");
   2.148 +    check(mapMaxValue(g, composeMap(functorToMap(&createC), map2)) == C('c'),
   2.149 +          "Wrong mapMaxValue()");
   2.150 +
   2.151 +    // mapFind(), mapFindIf()
   2.152 +    check(mapFind(g, map1, 5) == n2, "Wrong mapFind()");
   2.153 +    check(mapFind(g, map1, 6) == INVALID, "Wrong mapFind()");
   2.154 +    check(mapFind(g, map2, 'a') == a2, "Wrong mapFind()");
   2.155 +    check(mapFind(g, map2, 'e') == INVALID, "Wrong mapFind()");
   2.156 +    check(mapFind(g, cmap2, C(0)) == ArcIt(g), "Wrong mapFind()");
   2.157 +    check(mapFind(g, cmap2, C(1)) == INVALID, "Wrong mapFind()");
   2.158 +
   2.159 +    check(mapFindIf(g, map1, Less<int>(7)) == n2,
   2.160 +          "Wrong mapFindIf()");
   2.161 +    check(mapFindIf(g, map1, Less<int>(5)) == INVALID,
   2.162 +          "Wrong mapFindIf()");
   2.163 +    check(mapFindIf(g, map2, Less<char>('d')) == ArcIt(g),
   2.164 +          "Wrong mapFindIf()");
   2.165 +    check(mapFindIf(g, map2, Less<char>('a')) == INVALID,
   2.166 +          "Wrong mapFindIf()");
   2.167 +
   2.168 +    // mapCount(), mapCountIf()
   2.169 +    check(mapCount(g, map1, 5) == 1, "Wrong mapCount()");
   2.170 +    check(mapCount(g, map1, 6) == 0, "Wrong mapCount()");
   2.171 +    check(mapCount(g, map2, 'a') == 1, "Wrong mapCount()");
   2.172 +    check(mapCount(g, map2, 'b') == 2, "Wrong mapCount()");
   2.173 +    check(mapCount(g, map2, 'e') == 0, "Wrong mapCount()");
   2.174 +    check(mapCount(g, cmap2, C(0)) == 4, "Wrong mapCount()");
   2.175 +    check(mapCount(g, cmap2, C(1)) == 0, "Wrong mapCount()");
   2.176 +
   2.177 +    check(mapCountIf(g, map1, Less<int>(11)) == 2,
   2.178 +          "Wrong mapCountIf()");
   2.179 +    check(mapCountIf(g, map1, Less<int>(13)) == 3,
   2.180 +          "Wrong mapCountIf()");
   2.181 +    check(mapCountIf(g, map1, Less<int>(5)) == 0,
   2.182 +          "Wrong mapCountIf()");
   2.183 +    check(mapCountIf(g, map2, Less<char>('d')) == 4,
   2.184 +          "Wrong mapCountIf()");
   2.185 +    check(mapCountIf(g, map2, Less<char>('c')) == 3,
   2.186 +          "Wrong mapCountIf()");
   2.187 +    check(mapCountIf(g, map2, Less<char>('a')) == 0,
   2.188 +          "Wrong mapCountIf()");
   2.189 +     
   2.190 +    // MapIt, ConstMapIt
   2.191 +/*
   2.192 +These tests can be used after applying bugfix #330
   2.193 +    typedef SmartDigraph::NodeMap<int>::MapIt MapIt;
   2.194 +    typedef SmartDigraph::NodeMap<int>::ConstMapIt ConstMapIt;
   2.195 +    check(*std::min_element(MapIt(map1), MapIt(INVALID)) == 5,
   2.196 +          "Wrong NodeMap<>::MapIt");
   2.197 +    check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12,
   2.198 +          "Wrong NodeMap<>::MapIt");
   2.199 +    
   2.200 +    int sum = 0;
   2.201 +    std::for_each(MapIt(map1), MapIt(INVALID), Sum<int>(sum));
   2.202 +    check(sum == 27, "Wrong NodeMap<>::MapIt");
   2.203 +    std::for_each(ConstMapIt(map1), ConstMapIt(INVALID), Sum<int>(sum));
   2.204 +    check(sum == 54, "Wrong NodeMap<>::ConstMapIt");
   2.205 +*/
   2.206 +
   2.207 +    // mapCopy(), mapCompare(), mapFill()
   2.208 +    check(mapCompare(g, map1, map1), "Wrong mapCompare()");
   2.209 +    check(mapCompare(g, cmap2, cmap2), "Wrong mapCompare()");
   2.210 +    check(mapCompare(g, map1, shiftMap(map1, 0)), "Wrong mapCompare()");
   2.211 +    check(mapCompare(g, map2, scaleMap(map2, 1)), "Wrong mapCompare()");
   2.212 +    check(!mapCompare(g, map1, shiftMap(map1, 1)), "Wrong mapCompare()");
   2.213 +
   2.214 +    SmartDigraph::NodeMap<int> map3(g, 0);
   2.215 +    SmartDigraph::ArcMap<char> map4(g, 'a');
   2.216 +    
   2.217 +    check(!mapCompare(g, map1, map3), "Wrong mapCompare()");
   2.218 +    check(!mapCompare(g, map2, map4), "Wrong mapCompare()");    
   2.219 +    
   2.220 +    mapCopy(g, map1, map3);
   2.221 +    mapCopy(g, map2, map4);
   2.222 +
   2.223 +    check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()");
   2.224 +    check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()");    
   2.225 +    
   2.226 +    Undirector<SmartDigraph> ug(g);
   2.227 +    Undirector<SmartDigraph>::EdgeMap<char> umap1(ug, 'x');
   2.228 +    Undirector<SmartDigraph>::ArcMap<double> umap2(ug, 3.14);
   2.229 +    
   2.230 +    check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
   2.231 +    check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
   2.232 +    check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
   2.233 +    check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
   2.234 +    
   2.235 +    mapCopy(g, map2, umap1);
   2.236 +
   2.237 +    check(mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()");
   2.238 +    check(mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()");
   2.239 +    check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()");
   2.240 +    check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()");
   2.241 +    
   2.242 +    mapCopy(g, map2, umap1);
   2.243 +    mapCopy(g, umap1, map2);
   2.244 +    mapCopy(ug, map2, umap1);
   2.245 +    mapCopy(ug, umap1, map2);
   2.246 +    
   2.247 +    check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
   2.248 +    mapCopy(ug, umap1, umap2);
   2.249 +    check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()");
   2.250 +    
   2.251 +    check(!mapCompare(g, map1, constMap<Node>(2)), "Wrong mapCompare()");
   2.252 +    mapFill(g, map1, 2);
   2.253 +    check(mapCompare(g, constMap<Node>(2), map1), "Wrong mapFill()");
   2.254 +
   2.255 +    check(!mapCompare(g, map2, constMap<Arc>('z')), "Wrong mapCompare()");
   2.256 +    mapCopy(g, constMap<Arc>('z'), map2);
   2.257 +    check(mapCompare(g, constMap<Arc>('z'), map2), "Wrong mapCopy()");
   2.258 +  }
   2.259 +  
   2.260    return 0;
   2.261  }