Changeset 51:90201bb15a8d in lemonmain for lemon/maps.h
 Timestamp:
 01/08/08 20:26:48 (14 years ago)
 Branch:
 default
 Parents:
 50:a34c58ff6e40 (diff), 48:93ae269876de (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.  Phase:
 public
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

lemon/maps.h
r47 r51 3 3 * This file is a part of LEMON, a generic C++ optimization library 4 4 * 5 * Copyright (C) 2003200 75 * Copyright (C) 20032008 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 173 173 174 174 typedef MapBase<K, T> Parent; 175 /// \e176 typedef typename Parent::Key Key; 177 /// \e178 typedef typename Parent::Value Value; 179 /// \e175 ///Key type 176 typedef typename Parent::Key Key; 177 ///Value type 178 typedef typename Parent::Value Value; 179 ///Reference Type 180 180 typedef T& Reference; 181 /// \e181 ///Const reference type 182 182 typedef const T& ConstReference; 183 183 
lemon/maps.h
r44 r51 82 82 /// Constant map. 83 83 84 /// This is a readable map which assigns a specified value to each key. 85 /// In other aspects it is equivalent to the \c NullMap. 84 /// This is a \ref concepts::ReadMap "readable" map which assigns a 85 /// specified value to each key. 86 /// In other aspects it is equivalent to \c NullMap. 86 87 template<typename K, typename T> 87 88 class ConstMap : public MapBase<K, T> { … … 134 135 /// Constant map with inlined constant value. 135 136 136 /// This is a readable map which assigns a specified value to each key. 137 /// In other aspects it is equivalent to the \c NullMap. 137 /// This is a \ref concepts::ReadMap "readable" map which assigns a 138 /// specified value to each key. 139 /// In other aspects it is equivalent to \c NullMap. 138 140 template<typename K, typename V, V v> 139 141 class ConstMap<K, Const<V, v> > : public MapBase<K, V> { … … 150 152 }; 151 153 152 ///Returns a \c ConstMap class 154 ///Returns a \c ConstMap class with inlined value 153 155 154 156 ///This function just returns a \c ConstMap class with inlined value. … … 159 161 } 160 162 161 ///Map based on std::map163 ///Map based on \c std::map 162 164 163 165 ///This is essentially a wrapper for \c std::map with addition that 164 166 ///you can specify a default value different from \c Value(). 167 ///It meets the \ref concepts::ReferenceMap "ReferenceMap" concept. 165 168 template <typename K, typename T, typename Compare = std::less<K> > 166 class StdMap {169 class StdMap : public MapBase<K, T> { 167 170 template <typename K1, typename T1, typename C1> 168 171 friend class StdMap; 169 172 public: 170 173 171 typedef True ReferenceMapTag;174 typedef MapBase<K, T> Parent; 172 175 ///Key type 173 typedef KKey;176 typedef typename Parent::Key Key; 174 177 ///Value type 175 typedef TValue;178 typedef typename Parent::Value Value; 176 179 ///Reference Type 177 180 typedef T& Reference; 178 181 ///Const reference type 179 182 typedef const T& ConstReference; 183 184 typedef True ReferenceMapTag; 180 185 181 186 private: … … 189 194 /// Constructor with specified default value 190 195 StdMap(const T& value = T()) : _value(value) {} 191 /// \brief Constructs the map from an appropriate std::map, and explicitly192 /// specifies a default value.196 /// \brief Constructs the map from an appropriate \c std::map, and 197 /// explicitly specifies a default value. 193 198 template <typename T1, typename Comp1> 194 199 StdMap(const std::map<Key, T1, Comp1> &map, const T& value = T()) 195 200 : _map(map.begin(), map.end()), _value(value) {} 196 201 197 /// \brief Constructs a map from an other StdMap.202 /// \brief Constructs a map from an other \ref StdMap. 198 203 template<typename T1, typename Comp1> 199 204 StdMap(const StdMap<Key, T1, Comp1> &c) … … 240 245 241 246 }; 247 248 ///Returns a \c StdMap class 249 250 ///This function just returns a \c StdMap class with specified 251 ///default value. 252 ///\relates StdMap 253 template<typename K, typename V, typename Compare = std::less<K> > 254 inline StdMap<K, V, Compare> stdMap(const V& value = V()) { 255 return StdMap<K, V, Compare>(value); 256 } 257 258 ///Returns a \c StdMap class created from an appropriate std::map 259 260 ///This function just returns a \c StdMap class created from an 261 ///appropriate std::map. 262 ///\relates StdMap 263 template<typename K, typename V, typename Compare = std::less<K> > 264 inline StdMap<K, V, Compare> stdMap( const std::map<K, V, Compare> &map, 265 const V& value = V() ) { 266 return StdMap<K, V, Compare>(map, value); 267 } 242 268 243 269 /// \brief Map for storing values for keys from the range <tt>[0..size1]</tt> 244 270 /// 245 /// Th e currentmap has the <tt>[0..size1]</tt> keyset and the values271 /// This map has the <tt>[0..size1]</tt> keyset and the values 246 272 /// are stored in a \c std::vector<T> container. It can be used with 247 273 /// some data structures, for example \c UnionFind, \c BinHeap, when 248 /// the used items are small integer numbers. 274 /// the used items are small integer numbers. 275 /// This map meets the \ref concepts::ReferenceMap "ReferenceMap" concept. 249 276 /// 250 277 /// \todo Revise its name 251 278 template <typename T> 252 class IntegerMap {279 class IntegerMap : public MapBase<int, T> { 253 280 254 281 template <typename T1> … … 257 284 public: 258 285 286 typedef MapBase<int, T> Parent; 287 ///\e 288 typedef typename Parent::Key Key; 289 ///\e 290 typedef typename Parent::Value Value; 291 ///\e 292 typedef T& Reference; 293 ///\e 294 typedef const T& ConstReference; 295 259 296 typedef True ReferenceMapTag; 260 ///\e261 typedef int Key;262 ///\e263 typedef T Value;264 ///\e265 typedef T& Reference;266 ///\e267 typedef const T& ConstReference;268 297 269 298 private: … … 277 306 IntegerMap(int size = 0, const T& value = T()) : _vector(size, value) {} 278 307 279 /// \brief Constructs the map from an appropriate std::vector.308 /// \brief Constructs the map from an appropriate \c std::vector. 280 309 template <typename T1> 281 310 IntegerMap(const std::vector<T1>& vector) 282 311 : _vector(vector.begin(), vector.end()) {} 283 312 284 /// \brief Constructs a map from an other IntegerMap.313 /// \brief Constructs a map from an other \ref IntegerMap. 285 314 template <typename T1> 286 315 IntegerMap(const IntegerMap<T1> &c) … … 314 343 315 344 }; 345 346 ///Returns an \c IntegerMap class 347 348 ///This function just returns an \c IntegerMap class. 349 ///\relates IntegerMap 350 template<typename T> 351 inline IntegerMap<T> integerMap(int size = 0, const T& value = T()) { 352 return IntegerMap<T>(size, value); 353 } 316 354 317 355 /// @} … … 350 388 ///the default conversion. 351 389 /// 352 ///This \ cconcepts::ReadMap "read only map"390 ///This \ref concepts::ReadMap "read only map" 353 391 ///converts the \c Value of a map to type \c T. 354 392 ///Its \c Key is inherited from \c M. … … 367 405 ConvertMap(const M &_m) : m(_m) {}; 368 406 369 /// \brief The subscript operator. 370 /// 371 /// The subscript operator. 407 ///\e 372 408 Value operator[](const Key& k) const {return m[k];} 373 409 }; … … 406 442 Value operator[](Key k) const {return m[k];} 407 443 }; 444 445 ///Returns a \c SimpleMap class 446 447 ///This function just returns a \c SimpleMap class. 448 ///\relates SimpleMap 449 template<typename M> 450 inline SimpleMap<M> simpleMap(const M &m) { 451 return SimpleMap<M>(m); 452 } 408 453 409 454 ///Simple writable wrapping of a map 410 455 411 ///This \ref concepts:: WriteMap "write map" returns the simple456 ///This \ref concepts::ReadWriteMap "readwrite map" returns the simple 412 457 ///wrapping of the given map. Sometimes the reference maps cannot be 413 458 ///combined with simple readwrite maps. This map adaptor wraps the … … 434 479 }; 435 480 481 ///Returns a \c SimpleWriteMap class 482 483 ///This function just returns a \c SimpleWriteMap class. 484 ///\relates SimpleWriteMap 485 template<typename M> 486 inline SimpleWriteMap<M> simpleWriteMap(M &m) { 487 return SimpleWriteMap<M>(m); 488 } 489 436 490 ///Sum of two maps 437 491 438 ///This \ cconcepts::ReadMap "read only map" returns the sum of the two492 ///This \ref concepts::ReadMap "read only map" returns the sum of the two 439 493 ///given maps. 440 494 ///Its \c Key and \c Value are inherited from \c M1. 441 ///The \c Key and \c Value of M2 must be convertible to those of \c M1.495 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. 442 496 template<typename M1, typename M2> 443 497 class AddMap : public MapBase<typename M1::Key, typename M1::Value> { … … 459 513 460 514 ///This function just returns an \c AddMap class. 461 ///\todo How to call these type of functions?515 ///\todo Extend the documentation: how to call these type of functions? 462 516 /// 463 517 ///\relates AddMap … … 469 523 ///Shift a map with a constant. 470 524 471 ///This \ cconcepts::ReadMap "read only map" returns the sum of the525 ///This \ref concepts::ReadMap "read only map" returns the sum of the 472 526 ///given map and a constant value. 473 527 ///Its \c Key and \c Value are inherited from \c M. … … 505 559 ///Shift a map with a constant (ReadWrite version). 506 560 507 ///This \ cconcepts::ReadWriteMap "readwrite map" returns the sum of the561 ///This \ref concepts::ReadWriteMap "readwrite map" returns the sum of the 508 562 ///given map and a constant value. It makes also possible to write the map. 509 563 ///Its \c Key and \c Value are inherited from \c M. … … 551 605 ///Difference of two maps 552 606 553 ///This \ cconcepts::ReadMap "read only map" returns the difference607 ///This \ref concepts::ReadMap "read only map" returns the difference 554 608 ///of the values of the two given maps. 555 609 ///Its \c Key and \c Value are inherited from \c M1. … … 584 638 ///Product of two maps 585 639 586 ///This \ cconcepts::ReadMap "read only map" returns the product of the640 ///This \ref concepts::ReadMap "read only map" returns the product of the 587 641 ///values of the two given maps. 588 642 ///Its \c Key and \c Value are inherited from \c M1. … … 614 668 ///Scales a map with a constant. 615 669 616 ///This \ cconcepts::ReadMap "read only map" returns the value of the670 ///This \ref concepts::ReadMap "read only map" returns the value of the 617 671 ///given map multiplied from the left side with a constant value. 618 672 ///Its \c Key and \c Value are inherited from \c M. … … 650 704 ///Scales a map with a constant (ReadWrite version). 651 705 652 ///This \ cconcepts::ReadWriteMap "readwrite map" returns the value of the706 ///This \ref concepts::ReadWriteMap "readwrite map" returns the value of the 653 707 ///given map multiplied from the left side with a constant value. It can 654 708 ///also be used as write map if the \c / operator is defined between … … 698 752 ///Quotient of two maps 699 753 700 ///This \ cconcepts::ReadMap "read only map" returns the quotient of the754 ///This \ref concepts::ReadMap "read only map" returns the quotient of the 701 755 ///values of the two given maps. 702 756 ///Its \c Key and \c Value are inherited from \c M1. … … 728 782 ///Composition of two maps 729 783 730 ///This \ cconcepts::ReadMap "read only map" returns the composition of784 ///This \ref concepts::ReadMap "read only map" returns the composition of 731 785 ///two given maps. 732 786 ///That is to say, if \c m1 is of type \c M1 and \c m2 is of \c M2, … … 779 833 ///Combine of two maps using an STL (binary) functor. 780 834 /// 781 ///This \ cconcepts::ReadMap "read only map" takes two maps and a835 ///This \ref concepts::ReadMap "read only map" takes two maps and a 782 836 ///binary functor and returns the composition of the two 783 837 ///given maps unsing the functor. … … 852 906 ///Negative value of a map 853 907 854 ///This \ cconcepts::ReadMap "read only map" returns the negative908 ///This \ref concepts::ReadMap "read only map" returns the negative 855 909 ///value of the value returned by the given map. 856 910 ///Its \c Key and \c Value are inherited from \c M. … … 874 928 ///Negative value of a map (ReadWrite version) 875 929 876 ///This \ cconcepts::ReadWriteMap "readwrite map" returns the negative930 ///This \ref concepts::ReadWriteMap "readwrite map" returns the negative 877 931 ///value of the value returned by the given map. 878 932 ///Its \c Key and \c Value are inherited from \c M. … … 916 970 ///Absolute value of a map 917 971 918 ///This \ cconcepts::ReadMap "read only map" returns the absolute value972 ///This \ref concepts::ReadMap "read only map" returns the absolute value 919 973 ///of the value returned by the given map. 920 974 ///Its \c Key and \c Value are inherited from \c M. … … 950 1004 ///Converts an STL style functor to a map 951 1005 952 ///This \ cconcepts::ReadMap "read only map" returns the value1006 ///This \ref concepts::ReadMap "read only map" returns the value 953 1007 ///of a given functor. 954 1008 /// … … 956 1010 ///\c Key and \c Value. 957 1011 ///In most cases they have to be given explicitly because a 958 ///functor typically does not provide such typedefs. 1012 ///functor typically does not provide \c argument_type and 1013 ///\c result_type typedefs. 959 1014 /// 960 1015 ///Parameter \c F is the type of the used functor. … … 981 1036 ///This function just returns a \c FunctorMap class. 982 1037 /// 983 ///It is specialized for adaptable function classes and 984 ///C++ functions. 1038 ///This function is specialized for adaptable binary function 1039 ///classes and C++ functions. 1040 /// 985 1041 ///\relates FunctorMap 986 1042 template<typename K, typename V, typename F> inline … … 1005 1061 1006 1062 ///This class Converts a map to an STL style (unary) functor. 1007 /// that is it provides an <tt>operator()</tt> to read its values.1063 ///That is it provides an <tt>operator()</tt> to read its values. 1008 1064 /// 1009 1065 ///For the sake of convenience it also works as 1010 ///a ususal \ cconcepts::ReadMap "readable map",1066 ///a ususal \ref concepts::ReadMap "readable map", 1011 1067 ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist. 1012 1068 /// … … 1040 1096 } 1041 1097 1042 /// Applies all map setting operations to two maps1043 1044 ///This map has two \ cconcepts::ReadMap "readable map"1098 ///Just readable version of \ref ForkWriteMap 1099 1100 ///This map has two \ref concepts::ReadMap "readable map" 1045 1101 ///parameters and each read request will be passed just to the 1046 ///first map. This class is the just readable map type of theForkWriteMap.1102 ///first map. This class is the just readable map type of \c ForkWriteMap. 1047 1103 /// 1048 1104 ///The \c Key and \c Value are inherited from \c M1. 1049 ///The \c Key and \c Value of M2 must be convertible from those of \c M1.1105 ///The \c Key and \c Value of \c M2 must be convertible from those of \c M1. 1050 1106 /// 1051 1107 ///\sa ForkWriteMap … … 1070 1126 ///Applies all map setting operations to two maps 1071 1127 1072 ///This map has two \ cconcepts::WriteMap "writable map"1128 ///This map has two \ref concepts::WriteMap "writable map" 1073 1129 ///parameters and each write request will be passed to both of them. 1074 ///If \c M1 is also \ cconcepts::ReadMap "readable",1130 ///If \c M1 is also \ref concepts::ReadMap "readable", 1075 1131 ///then the read operations will return the 1076 1132 ///corresponding values of \c M1. 1077 1133 /// 1078 1134 ///The \c Key and \c Value are inherited from \c M1. 1079 ///The \c Key and \c Value of M2 must be convertible from those of \c M1.1135 ///The \c Key and \c Value of \c M2 must be convertible from those of \c M1. 1080 1136 /// 1081 1137 ///\sa ForkMap … … 1121 1177 ///Logical 'not' of a map 1122 1178 1123 ///This bool \ cconcepts::ReadMap "read only map" returns the1179 ///This bool \ref concepts::ReadMap "read only map" returns the 1124 1180 ///logical negation of the value returned by the given map. 1125 ///Its \c Key is inherited from \c M, its Value is \c bool.1181 ///Its \c Key is inherited from \c M, its \c Value is \c bool. 1126 1182 /// 1127 1183 ///\sa NotWriteMap … … 1142 1198 ///Logical 'not' of a map (ReadWrie version) 1143 1199 1144 ///This bool \ cconcepts::ReadWriteMap "readwrite map" returns the1200 ///This bool \ref concepts::ReadWriteMap "readwrite map" returns the 1145 1201 ///logical negation of the value returned by the given map. When it is set, 1146 1202 ///the opposite value is set to the original map. 1147 ///Its \c Key is inherited from \c M, its Value is \c bool.1203 ///Its \c Key is inherited from \c M, its \c Value is \c bool. 1148 1204 /// 1149 1205 ///\sa NotMap … … 1210 1266 /// \brief Writable bool map for logging each \c true assigned element 1211 1267 /// 1212 /// Writable bool map for logging each \c true assigned element, i.e it 1213 /// copies all the keys set to \c true to the given iterator. 1268 /// A \ref concepts::ReadWriteMap "readwrite" bool map for logging 1269 /// each \c true assigned element, i.e it copies all the keys set 1270 /// to \c true to the given iterator. 1214 1271 /// 1215 1272 /// \note The container of the iterator should contain space 1216 1273 /// for each element. 1217 1274 /// 1218 /// The following example shows how you can write the edges found by the Prim 1219 /// algorithm directly 1220 /// to the standard output. 1275 /// The following example shows how you can write the edges found by 1276 /// the \ref Prim algorithm directly to the standard output. 1221 1277 ///\code 1222 1278 /// typedef IdMap<Graph, Edge> EdgeIdMap;
Note: See TracChangeset
for help on using the changeset viewer.