gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Merge
0 1 0
merge default
0 files changed with 12 insertions and 9 deletions:
↑ Collapse diff ↑
Show white space 48 line context
... ...
@@ -23,51 +23,51 @@
23 23
#include <functional>
24 24
#include <vector>
25 25

	
26 26
#include <lemon/bits/utility.h>
27 27
// #include <lemon/bits/traits.h>
28 28

	
29 29
///\file
30 30
///\ingroup maps
31 31
///\brief Miscellaneous property maps
32 32
///
33 33
#include <map>
34 34

	
35 35
namespace lemon {
36 36

	
37 37
  /// \addtogroup maps
38 38
  /// @{
39 39

	
40 40
  /// Base class of maps.
41 41

	
42 42
  /// Base class of maps.
43 43
  /// It provides the necessary <tt>typedef</tt>s required by the map concept.
44 44
  template<typename K, typename T>
45 45
  class MapBase {
46 46
  public:
47
    ///\e
47
    /// The key type of the map.
48 48
    typedef K Key;
49
    ///\e
49
    /// The value type of the map. (The type of objects associated with the keys).
50 50
    typedef T Value;
51 51
  };
52 52

	
53 53
  /// Null map. (a.k.a. DoNothingMap)
54 54

	
55 55
  /// This map can be used if you have to provide a map only for
56 56
  /// its type definitions, or if you have to provide a writable map, 
57 57
  /// but data written to it is not required (i.e. it will be sent to 
58 58
  /// <tt>/dev/null</tt>).
59 59
  template<typename K, typename T>
60 60
  class NullMap : public MapBase<K, T> {
61 61
  public:
62 62
    typedef MapBase<K, T> Parent;
63 63
    typedef typename Parent::Key Key;
64 64
    typedef typename Parent::Value Value;
65 65
    
66 66
    /// Gives back a default constructed element.
67 67
    T operator[](const K&) const { return T(); }
68 68
    /// Absorbs the value.
69 69
    void set(const K&, const T&) {}
70 70
  };
71 71

	
72 72
  ///Returns a \c NullMap class
73 73

	
... ...
@@ -228,51 +228,51 @@
228 228
	return _value;
229 229
    }
230 230

	
231 231
    /// \e 
232 232
    void set(const Key &k, const T &t) {
233 233
      typename Map::iterator it = _map.lower_bound(k);
234 234
      if (it != _map.end() && !_map.key_comp()(k, it->first))
235 235
	it->second = t;
236 236
      else
237 237
	_map.insert(it, std::make_pair(k, t));
238 238
    }
239 239

	
240 240
    /// \e
241 241
    void setAll(const T &t) {
242 242
      _value = t;
243 243
      _map.clear();
244 244
    }    
245 245

	
246 246
    template <typename T1, typename C1 = std::less<T1> >
247 247
    struct rebind {
248 248
      typedef StdMap<Key, T1, C1> other;
249 249
    };
250 250
  };
251 251

	
252
  /// \brief Map for storing values for the range \c [0..size-1] range keys
252
  /// \brief Map for storing values for keys from the range <tt>[0..size-1]</tt>
253 253
  ///
254
  /// The current map has the \c [0..size-1] keyset and the values
254
  /// The current map has the <tt>[0..size-1]</tt> keyset and the values
255 255
  /// are stored in a \c std::vector<T>  container. It can be used with
256 256
  /// some data structures, for example \c UnionFind, \c BinHeap, when 
257 257
  /// the used items are small integer numbers. 
258 258
  ///
259 259
  /// \todo Revise its name
260 260
  template <typename T>
261 261
  class IntegerMap {
262 262

	
263 263
    template <typename T1>
264 264
    friend class IntegerMap;
265 265

	
266 266
  public:
267 267

	
268 268
    typedef True ReferenceMapTag;
269 269
    ///\e
270 270
    typedef int Key;
271 271
    ///\e
272 272
    typedef T Value;
273 273
    ///\e
274 274
    typedef T& Reference;
275 275
    ///\e
276 276
    typedef const T& ConstReference;
277 277

	
278 278
  private:
... ...
@@ -808,49 +808,49 @@
808 808
  template<typename M1, typename M2, typename F,
809 809
	   typename V = typename F::result_type> 
810 810
  class CombineMap : public MapBase<typename M1::Key, V> {
811 811
    const M1& m1;
812 812
    const M2& m2;
813 813
    F f;
814 814
  public:
815 815
    typedef MapBase<typename M1::Key, V> Parent;
816 816
    typedef typename Parent::Key Key;
817 817
    typedef typename Parent::Value Value;
818 818

	
819 819
    ///Constructor
820 820
    CombineMap(const M1 &_m1,const M2 &_m2,const F &_f = F())
821 821
      : m1(_m1), m2(_m2), f(_f) {};
822 822
    /// \e
823 823
    Value operator[](Key k) const {return f(m1[k],m2[k]);}
824 824
  };
825 825
  
826 826
  ///Returns a \c CombineMap class
827 827

	
828 828
  ///This function just returns a \c CombineMap class.
829 829
  ///
830 830
  ///For example if \c m1 and \c m2 are both \c double valued maps, then 
831 831
  ///\code
832
  ///combineMap<double>(m1,m2,std::plus<double>())
832
  ///combineMap(m1,m2,std::plus<double>())
833 833
  ///\endcode
834 834
  ///is equivalent to
835 835
  ///\code
836 836
  ///addMap(m1,m2)
837 837
  ///\endcode
838 838
  ///
839 839
  ///This function is specialized for adaptable binary function
840 840
  ///classes and C++ functions.
841 841
  ///
842 842
  ///\relates CombineMap
843 843
  template<typename M1, typename M2, typename F, typename V> 
844 844
  inline CombineMap<M1, M2, F, V> 
845 845
  combineMap(const M1& m1,const M2& m2, const F& f) {
846 846
    return CombineMap<M1, M2, F, V>(m1,m2,f);
847 847
  }
848 848

	
849 849
  template<typename M1, typename M2, typename F> 
850 850
  inline CombineMap<M1, M2, F, typename F::result_type> 
851 851
  combineMap(const M1& m1, const M2& m2, const F& f) {
852 852
    return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f);
853 853
  }
854 854

	
855 855
  template<typename M1, typename M2, typename K1, typename K2, typename V> 
856 856
  inline CombineMap<M1, M2, V (*)(K1, K2), V> 
... ...
@@ -941,50 +941,51 @@
941 941
    AbsMap(const M &_m) : m(_m) {};
942 942
    /// \e
943 943
    Value operator[](Key k) const {
944 944
      Value tmp = m[k]; 
945 945
      return tmp >= 0 ? tmp : -tmp;
946 946
    }
947 947

	
948 948
  };
949 949
  
950 950
  ///Returns an \c AbsMap class
951 951

	
952 952
  ///This function just returns an \c AbsMap class.
953 953
  ///\relates AbsMap
954 954
  template<typename M> 
955 955
  inline AbsMap<M> absMap(const M &m) {
956 956
    return AbsMap<M>(m);
957 957
  }
958 958

	
959 959
  ///Converts an STL style functor to a map
960 960

	
961 961
  ///This \c concepts::ReadMap "read only map" returns the value
962 962
  ///of a given functor.
963 963
  ///
964 964
  ///Template parameters \c K and \c V will become its
965
  ///\c Key and \c Value. They must be given explicitly
966
  ///because a functor does not provide such typedefs.
965
  ///\c Key and \c Value. 
966
  ///In most cases they have to be given explicitly because a 
967
  ///functor typically does not provide such typedefs.
967 968
  ///
968 969
  ///Parameter \c F is the type of the used functor.
969 970
  ///
970 971
  ///\sa MapFunctor
971 972
  template<typename F, 
972 973
	   typename K = typename F::argument_type, 
973 974
	   typename V = typename F::result_type> 
974 975
  class FunctorMap : public MapBase<K, V> {
975 976
    F f;
976 977
  public:
977 978
    typedef MapBase<K, V> Parent;
978 979
    typedef typename Parent::Key Key;
979 980
    typedef typename Parent::Value Value;
980 981

	
981 982
    ///Constructor
982 983
    FunctorMap(const F &_f = F()) : f(_f) {}
983 984
    /// \e
984 985
    Value operator[](Key k) const { return f(k);}
985 986
  };
986 987
  
987 988
  ///Returns a \c FunctorMap class
988 989

	
989 990
  ///This function just returns a \c FunctorMap class.
990 991
  ///
... ...
@@ -1219,48 +1220,50 @@
1219 1220
  ///
1220 1221
  /// Writable bool map for logging each \c true assigned element, i.e it
1221 1222
  /// copies all the keys set to \c true to the given iterator.
1222 1223
  ///
1223 1224
  /// \note The container of the iterator should contain space 
1224 1225
  /// for each element.
1225 1226
  ///
1226 1227
  /// The following example shows how you can write the edges found by the Prim
1227 1228
  /// algorithm directly
1228 1229
  /// to the standard output.
1229 1230
  ///\code
1230 1231
  /// typedef IdMap<Graph, Edge> EdgeIdMap;
1231 1232
  /// EdgeIdMap edgeId(graph);
1232 1233
  ///
1233 1234
  /// typedef MapFunctor<EdgeIdMap> EdgeIdFunctor;
1234 1235
  /// EdgeIdFunctor edgeIdFunctor(edgeId);
1235 1236
  ///
1236 1237
  /// StoreBoolMap<ostream_iterator<int>, EdgeIdFunctor> 
1237 1238
  ///   writerMap(ostream_iterator<int>(cout, " "), edgeIdFunctor);
1238 1239
  ///
1239 1240
  /// prim(graph, cost, writerMap);
1240 1241
  ///\endcode
1241 1242
  ///
1242 1243
  ///\sa BackInserterBoolMap 
1244
  ///\sa FrontInserterBoolMap 
1245
  ///\sa InserterBoolMap 
1243 1246
  ///
1244 1247
  ///\todo Revise the name of this class and the related ones.
1245 1248
  template <typename _Iterator, 
1246 1249
            typename _Functor =
1247 1250
            _maps_bits::Identity<typename _maps_bits::
1248 1251
                                 IteratorTraits<_Iterator>::Value> >
1249 1252
  class StoreBoolMap {
1250 1253
  public:
1251 1254
    typedef _Iterator Iterator;
1252 1255

	
1253 1256
    typedef typename _Functor::argument_type Key;
1254 1257
    typedef bool Value;
1255 1258

	
1256 1259
    typedef _Functor Functor;
1257 1260

	
1258 1261
    /// Constructor
1259 1262
    StoreBoolMap(Iterator it, const Functor& functor = Functor()) 
1260 1263
      : _begin(it), _end(it), _functor(functor) {}
1261 1264

	
1262 1265
    /// Gives back the given iterator set for the first key
1263 1266
    Iterator begin() const {
1264 1267
      return _begin;
1265 1268
    }
1266 1269
 
... ...
@@ -1284,84 +1287,84 @@
1284 1287

	
1285 1288
  /// \brief Writable bool map for logging each \c true assigned element in 
1286 1289
  /// a back insertable container.
1287 1290
  ///
1288 1291
  /// Writable bool map for logging each \c true assigned element by pushing
1289 1292
  /// them into a back insertable container.
1290 1293
  /// It can be used to retrieve the items into a standard
1291 1294
  /// container. The next example shows how you can store the
1292 1295
  /// edges found by the Prim algorithm in a vector.
1293 1296
  ///
1294 1297
  ///\code
1295 1298
  /// vector<Edge> span_tree_edges;
1296 1299
  /// BackInserterBoolMap<vector<Edge> > inserter_map(span_tree_edges);
1297 1300
  /// prim(graph, cost, inserter_map);
1298 1301
  ///\endcode
1299 1302
  ///
1300 1303
  ///\sa StoreBoolMap
1301 1304
  ///\sa FrontInserterBoolMap
1302 1305
  ///\sa InserterBoolMap
1303 1306
  template <typename Container,
1304 1307
            typename Functor =
1305 1308
            _maps_bits::Identity<typename Container::value_type> >
1306 1309
  class BackInserterBoolMap {
1307 1310
  public:
1308
    typedef typename Container::value_type Key;
1311
    typedef typename Functor::argument_type Key;
1309 1312
    typedef bool Value;
1310 1313

	
1311 1314
    /// Constructor
1312 1315
    BackInserterBoolMap(Container& _container, 
1313 1316
                        const Functor& _functor = Functor()) 
1314 1317
      : container(_container), functor(_functor) {}
1315 1318

	
1316 1319
    /// The \c set function of the map
1317 1320
    void set(const Key& key, Value value) {
1318 1321
      if (value) {
1319 1322
	container.push_back(functor(key));
1320 1323
      }
1321 1324
    }
1322 1325
    
1323 1326
  private:
1324 1327
    Container& container;
1325 1328
    Functor functor;
1326 1329
  };
1327 1330

	
1328 1331
  /// \brief Writable bool map for logging each \c true assigned element in 
1329 1332
  /// a front insertable container.
1330 1333
  ///
1331 1334
  /// Writable bool map for logging each \c true assigned element by pushing
1332 1335
  /// them into a front insertable container.
1333 1336
  /// It can be used to retrieve the items into a standard
1334 1337
  /// container. For example see \ref BackInserterBoolMap.
1335 1338
  ///
1336 1339
  ///\sa BackInserterBoolMap
1337 1340
  ///\sa InserterBoolMap
1338 1341
  template <typename Container,
1339 1342
            typename Functor =
1340 1343
            _maps_bits::Identity<typename Container::value_type> >
1341 1344
  class FrontInserterBoolMap {
1342 1345
  public:
1343
    typedef typename Container::value_type Key;
1346
    typedef typename Functor::argument_type Key;
1344 1347
    typedef bool Value;
1345 1348

	
1346 1349
    /// Constructor
1347 1350
    FrontInserterBoolMap(Container& _container,
1348 1351
                         const Functor& _functor = Functor()) 
1349 1352
      : container(_container), functor(_functor) {}
1350 1353

	
1351 1354
    /// The \c set function of the map
1352 1355
    void set(const Key& key, Value value) {
1353 1356
      if (value) {
1354 1357
	container.push_front(functor(key));
1355 1358
      }
1356 1359
    }
1357 1360
    
1358 1361
  private:
1359 1362
    Container& container;    
1360 1363
    Functor functor;
1361 1364
  };
1362 1365

	
1363 1366
  /// \brief Writable bool map for storing each \c true assigned element in 
1364 1367
  /// an insertable container.
1365 1368
  ///
1366 1369
  /// Writable bool map for storing each \c true assigned element in an 
1367 1370
  /// insertable container. It will insert all the keys set to \c true into
0 comments (0 inline)