Changes in / [51:90201bb15a8d:50:a34c58ff6e40] in lemon-main
- Location:
- lemon
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/concepts/maps.h
r51 r39 49 49 /// Returns the value associated with a key. 50 50 51 /// Returns the value associated with a key.52 51 /// \bug Value shouldn't need to be default constructible. 53 52 /// … … 115 114 }; 116 115 117 /// Read/ writable map concept116 /// Read/Writable map concept 118 117 119 118 /// Read/writable map concept. … … 148 147 /// Dereferable map concept. 149 148 /// 150 /// \todo Rethink this concept.151 149 template<typename K, typename T, typename R, typename CR> 152 150 class ReferenceMap : public ReadWriteMap<K,T> … … 168 166 public: 169 167 170 ///Returns a reference to the value associated witha key.168 ///Returns a reference to the value associated to a key. 171 169 Reference operator[](const Key &) { return tmp; } 172 ///Returns a const reference to the value associated witha key.170 ///Returns a const reference to the value associated to a key. 173 171 ConstReference operator[](const Key &) const { return tmp; } 174 172 /// Sets the value associated with a key. 175 173 void set(const Key &k,const Value &t) { operator[](k)=t; } 176 174 175 /// \todo Rethink this concept. 177 176 template<typename _ReferenceMap> 178 177 struct ReferenceMapConcept { -
lemon/maps.h
r51 r44 82 82 /// Constant map. 83 83 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. 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. 87 86 template<typename K, typename T> 88 87 class ConstMap : public MapBase<K, T> { … … 135 134 /// Constant map with inlined constant value. 136 135 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. 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. 140 138 template<typename K, typename V, V v> 141 139 class ConstMap<K, Const<V, v> > : public MapBase<K, V> { … … 152 150 }; 153 151 154 ///Returns a \c ConstMap class with inlined value152 ///Returns a \c ConstMap class 155 153 156 154 ///This function just returns a \c ConstMap class with inlined value. … … 161 159 } 162 160 163 ///Map based on \cstd::map161 ///Map based on std::map 164 162 165 163 ///This is essentially a wrapper for \c std::map with addition that 166 164 ///you can specify a default value different from \c Value(). 167 ///It meets the \ref concepts::ReferenceMap "ReferenceMap" concept.168 165 template <typename K, typename T, typename Compare = std::less<K> > 169 class StdMap : public MapBase<K, T>{166 class StdMap { 170 167 template <typename K1, typename T1, typename C1> 171 168 friend class StdMap; 172 169 public: 173 170 174 typedef MapBase<K, T> Parent;171 typedef True ReferenceMapTag; 175 172 ///Key type 176 typedef typename Parent::KeyKey;173 typedef K Key; 177 174 ///Value type 178 typedef typename Parent::ValueValue;175 typedef T Value; 179 176 ///Reference Type 180 177 typedef T& Reference; 181 178 ///Const reference type 182 179 typedef const T& ConstReference; 183 184 typedef True ReferenceMapTag;185 180 186 181 private: … … 194 189 /// Constructor with specified default value 195 190 StdMap(const T& value = T()) : _value(value) {} 196 /// \brief Constructs the map from an appropriate \c std::map, and197 /// explicitlyspecifies a default value.191 /// \brief Constructs the map from an appropriate std::map, and explicitly 192 /// specifies a default value. 198 193 template <typename T1, typename Comp1> 199 194 StdMap(const std::map<Key, T1, Comp1> &map, const T& value = T()) 200 195 : _map(map.begin(), map.end()), _value(value) {} 201 196 202 /// \brief Constructs a map from an other \refStdMap.197 /// \brief Constructs a map from an other StdMap. 203 198 template<typename T1, typename Comp1> 204 199 StdMap(const StdMap<Key, T1, Comp1> &c) … … 245 240 246 241 }; 247 248 ///Returns a \c StdMap class249 250 ///This function just returns a \c StdMap class with specified251 ///default value.252 ///\relates StdMap253 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::map259 260 ///This function just returns a \c StdMap class created from an261 ///appropriate std::map.262 ///\relates StdMap263 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 }268 242 269 243 /// \brief Map for storing values for keys from the range <tt>[0..size-1]</tt> 270 244 /// 271 /// Th ismap has the <tt>[0..size-1]</tt> keyset and the values245 /// The current map has the <tt>[0..size-1]</tt> keyset and the values 272 246 /// are stored in a \c std::vector<T> container. It can be used with 273 247 /// some data structures, for example \c UnionFind, \c BinHeap, when 274 /// the used items are small integer numbers. 275 /// This map meets the \ref concepts::ReferenceMap "ReferenceMap" concept. 248 /// the used items are small integer numbers. 276 249 /// 277 250 /// \todo Revise its name 278 251 template <typename T> 279 class IntegerMap : public MapBase<int, T>{252 class IntegerMap { 280 253 281 254 template <typename T1> … … 284 257 public: 285 258 286 typedef MapBase<int, T> Parent;287 ///\e 288 typedef typename Parent::KeyKey;289 ///\e 290 typedef typename Parent::ValueValue;259 typedef True ReferenceMapTag; 260 ///\e 261 typedef int Key; 262 ///\e 263 typedef T Value; 291 264 ///\e 292 265 typedef T& Reference; 293 266 ///\e 294 267 typedef const T& ConstReference; 295 296 typedef True ReferenceMapTag;297 268 298 269 private: … … 306 277 IntegerMap(int size = 0, const T& value = T()) : _vector(size, value) {} 307 278 308 /// \brief Constructs the map from an appropriate \cstd::vector.279 /// \brief Constructs the map from an appropriate std::vector. 309 280 template <typename T1> 310 281 IntegerMap(const std::vector<T1>& vector) 311 282 : _vector(vector.begin(), vector.end()) {} 312 283 313 /// \brief Constructs a map from an other \refIntegerMap.284 /// \brief Constructs a map from an other IntegerMap. 314 285 template <typename T1> 315 286 IntegerMap(const IntegerMap<T1> &c) … … 343 314 344 315 }; 345 346 ///Returns an \c IntegerMap class347 348 ///This function just returns an \c IntegerMap class.349 ///\relates IntegerMap350 template<typename T>351 inline IntegerMap<T> integerMap(int size = 0, const T& value = T()) {352 return IntegerMap<T>(size, value);353 }354 316 355 317 /// @} … … 388 350 ///the default conversion. 389 351 /// 390 ///This \ refconcepts::ReadMap "read only map"352 ///This \c concepts::ReadMap "read only map" 391 353 ///converts the \c Value of a map to type \c T. 392 354 ///Its \c Key is inherited from \c M. … … 405 367 ConvertMap(const M &_m) : m(_m) {}; 406 368 407 ///\e 369 /// \brief The subscript operator. 370 /// 371 /// The subscript operator. 408 372 Value operator[](const Key& k) const {return m[k];} 409 373 }; … … 442 406 Value operator[](Key k) const {return m[k];} 443 407 }; 444 445 ///Returns a \c SimpleMap class446 447 ///This function just returns a \c SimpleMap class.448 ///\relates SimpleMap449 template<typename M>450 inline SimpleMap<M> simpleMap(const M &m) {451 return SimpleMap<M>(m);452 }453 408 454 409 ///Simple writable wrapping of a map 455 410 456 ///This \ref concepts:: ReadWriteMap "read-write map" returns the simple411 ///This \ref concepts::WriteMap "write map" returns the simple 457 412 ///wrapping of the given map. Sometimes the reference maps cannot be 458 413 ///combined with simple read-write maps. This map adaptor wraps the … … 479 434 }; 480 435 481 ///Returns a \c SimpleWriteMap class482 483 ///This function just returns a \c SimpleWriteMap class.484 ///\relates SimpleWriteMap485 template<typename M>486 inline SimpleWriteMap<M> simpleWriteMap(M &m) {487 return SimpleWriteMap<M>(m);488 }489 490 436 ///Sum of two maps 491 437 492 ///This \ refconcepts::ReadMap "read only map" returns the sum of the two438 ///This \c concepts::ReadMap "read only map" returns the sum of the two 493 439 ///given maps. 494 440 ///Its \c Key and \c Value are inherited from \c M1. 495 ///The \c Key and \c Value of \cM2 must be convertible to those of \c M1.441 ///The \c Key and \c Value of M2 must be convertible to those of \c M1. 496 442 template<typename M1, typename M2> 497 443 class AddMap : public MapBase<typename M1::Key, typename M1::Value> { … … 513 459 514 460 ///This function just returns an \c AddMap class. 515 ///\todo Extend the documentation: how to call these type of functions?461 ///\todo How to call these type of functions? 516 462 /// 517 463 ///\relates AddMap … … 523 469 ///Shift a map with a constant. 524 470 525 ///This \ refconcepts::ReadMap "read only map" returns the sum of the471 ///This \c concepts::ReadMap "read only map" returns the sum of the 526 472 ///given map and a constant value. 527 473 ///Its \c Key and \c Value are inherited from \c M. … … 559 505 ///Shift a map with a constant (ReadWrite version). 560 506 561 ///This \ refconcepts::ReadWriteMap "read-write map" returns the sum of the507 ///This \c concepts::ReadWriteMap "read-write map" returns the sum of the 562 508 ///given map and a constant value. It makes also possible to write the map. 563 509 ///Its \c Key and \c Value are inherited from \c M. … … 605 551 ///Difference of two maps 606 552 607 ///This \ refconcepts::ReadMap "read only map" returns the difference553 ///This \c concepts::ReadMap "read only map" returns the difference 608 554 ///of the values of the two given maps. 609 555 ///Its \c Key and \c Value are inherited from \c M1. … … 638 584 ///Product of two maps 639 585 640 ///This \ refconcepts::ReadMap "read only map" returns the product of the586 ///This \c concepts::ReadMap "read only map" returns the product of the 641 587 ///values of the two given maps. 642 588 ///Its \c Key and \c Value are inherited from \c M1. … … 668 614 ///Scales a map with a constant. 669 615 670 ///This \ refconcepts::ReadMap "read only map" returns the value of the616 ///This \c concepts::ReadMap "read only map" returns the value of the 671 617 ///given map multiplied from the left side with a constant value. 672 618 ///Its \c Key and \c Value are inherited from \c M. … … 704 650 ///Scales a map with a constant (ReadWrite version). 705 651 706 ///This \ refconcepts::ReadWriteMap "read-write map" returns the value of the652 ///This \c concepts::ReadWriteMap "read-write map" returns the value of the 707 653 ///given map multiplied from the left side with a constant value. It can 708 654 ///also be used as write map if the \c / operator is defined between … … 752 698 ///Quotient of two maps 753 699 754 ///This \ refconcepts::ReadMap "read only map" returns the quotient of the700 ///This \c concepts::ReadMap "read only map" returns the quotient of the 755 701 ///values of the two given maps. 756 702 ///Its \c Key and \c Value are inherited from \c M1. … … 782 728 ///Composition of two maps 783 729 784 ///This \ refconcepts::ReadMap "read only map" returns the composition of730 ///This \c concepts::ReadMap "read only map" returns the composition of 785 731 ///two given maps. 786 732 ///That is to say, if \c m1 is of type \c M1 and \c m2 is of \c M2, … … 833 779 ///Combine of two maps using an STL (binary) functor. 834 780 /// 835 ///This \ refconcepts::ReadMap "read only map" takes two maps and a781 ///This \c concepts::ReadMap "read only map" takes two maps and a 836 782 ///binary functor and returns the composition of the two 837 783 ///given maps unsing the functor. … … 906 852 ///Negative value of a map 907 853 908 ///This \ refconcepts::ReadMap "read only map" returns the negative854 ///This \c concepts::ReadMap "read only map" returns the negative 909 855 ///value of the value returned by the given map. 910 856 ///Its \c Key and \c Value are inherited from \c M. … … 928 874 ///Negative value of a map (ReadWrite version) 929 875 930 ///This \ refconcepts::ReadWriteMap "read-write map" returns the negative876 ///This \c concepts::ReadWriteMap "read-write map" returns the negative 931 877 ///value of the value returned by the given map. 932 878 ///Its \c Key and \c Value are inherited from \c M. … … 970 916 ///Absolute value of a map 971 917 972 ///This \ refconcepts::ReadMap "read only map" returns the absolute value918 ///This \c concepts::ReadMap "read only map" returns the absolute value 973 919 ///of the value returned by the given map. 974 920 ///Its \c Key and \c Value are inherited from \c M. … … 1004 950 ///Converts an STL style functor to a map 1005 951 1006 ///This \ refconcepts::ReadMap "read only map" returns the value952 ///This \c concepts::ReadMap "read only map" returns the value 1007 953 ///of a given functor. 1008 954 /// … … 1010 956 ///\c Key and \c Value. 1011 957 ///In most cases they have to be given explicitly because a 1012 ///functor typically does not provide \c argument_type and 1013 ///\c result_type typedefs. 958 ///functor typically does not provide such typedefs. 1014 959 /// 1015 960 ///Parameter \c F is the type of the used functor. … … 1036 981 ///This function just returns a \c FunctorMap class. 1037 982 /// 1038 ///This function is specialized for adaptable binary function 1039 ///classes and C++ functions. 1040 /// 983 ///It is specialized for adaptable function classes and 984 ///C++ functions. 1041 985 ///\relates FunctorMap 1042 986 template<typename K, typename V, typename F> inline … … 1061 1005 1062 1006 ///This class Converts a map to an STL style (unary) functor. 1063 /// That is it provides an <tt>operator()</tt> to read its values.1007 ///that is it provides an <tt>operator()</tt> to read its values. 1064 1008 /// 1065 1009 ///For the sake of convenience it also works as 1066 ///a ususal \ refconcepts::ReadMap "readable map",1010 ///a ususal \c concepts::ReadMap "readable map", 1067 1011 ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist. 1068 1012 /// … … 1096 1040 } 1097 1041 1098 /// Just readable version of \ref ForkWriteMap1099 1100 ///This map has two \ refconcepts::ReadMap "readable map"1042 ///Applies all map setting operations to two maps 1043 1044 ///This map has two \c concepts::ReadMap "readable map" 1101 1045 ///parameters and each read request will be passed just to the 1102 ///first map. This class is the just readable map type of \cForkWriteMap.1046 ///first map. This class is the just readable map type of the ForkWriteMap. 1103 1047 /// 1104 1048 ///The \c Key and \c Value are inherited from \c M1. 1105 ///The \c Key and \c Value of \cM2 must be convertible from those of \c M1.1049 ///The \c Key and \c Value of M2 must be convertible from those of \c M1. 1106 1050 /// 1107 1051 ///\sa ForkWriteMap … … 1126 1070 ///Applies all map setting operations to two maps 1127 1071 1128 ///This map has two \ refconcepts::WriteMap "writable map"1072 ///This map has two \c concepts::WriteMap "writable map" 1129 1073 ///parameters and each write request will be passed to both of them. 1130 ///If \c M1 is also \ refconcepts::ReadMap "readable",1074 ///If \c M1 is also \c concepts::ReadMap "readable", 1131 1075 ///then the read operations will return the 1132 1076 ///corresponding values of \c M1. 1133 1077 /// 1134 1078 ///The \c Key and \c Value are inherited from \c M1. 1135 ///The \c Key and \c Value of \cM2 must be convertible from those of \c M1.1079 ///The \c Key and \c Value of M2 must be convertible from those of \c M1. 1136 1080 /// 1137 1081 ///\sa ForkMap … … 1177 1121 ///Logical 'not' of a map 1178 1122 1179 ///This bool \ refconcepts::ReadMap "read only map" returns the1123 ///This bool \c concepts::ReadMap "read only map" returns the 1180 1124 ///logical negation of the value returned by the given map. 1181 ///Its \c Key is inherited from \c M, its \cValue is \c bool.1125 ///Its \c Key is inherited from \c M, its Value is \c bool. 1182 1126 /// 1183 1127 ///\sa NotWriteMap … … 1198 1142 ///Logical 'not' of a map (ReadWrie version) 1199 1143 1200 ///This bool \ refconcepts::ReadWriteMap "read-write map" returns the1144 ///This bool \c concepts::ReadWriteMap "read-write map" returns the 1201 1145 ///logical negation of the value returned by the given map. When it is set, 1202 1146 ///the opposite value is set to the original map. 1203 ///Its \c Key is inherited from \c M, its \cValue is \c bool.1147 ///Its \c Key is inherited from \c M, its Value is \c bool. 1204 1148 /// 1205 1149 ///\sa NotMap … … 1266 1210 /// \brief Writable bool map for logging each \c true assigned element 1267 1211 /// 1268 /// A \ref concepts::ReadWriteMap "read-write" 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. 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. 1271 1214 /// 1272 1215 /// \note The container of the iterator should contain space 1273 1216 /// for each element. 1274 1217 /// 1275 /// The following example shows how you can write the edges found by 1276 /// the \ref Prim algorithm directly to the standard output. 1218 /// The following example shows how you can write the edges found by the Prim 1219 /// algorithm directly 1220 /// to the standard output. 1277 1221 ///\code 1278 1222 /// typedef IdMap<Graph, Edge> EdgeIdMap;
Note: See TracChangeset
for help on using the changeset viewer.