Changeset 2511:a99186a9b6b0 in lemon0.x
 Timestamp:
 11/14/07 18:42:48 (16 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@3376
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

lemon/maps.h
r2489 r2511 22 22 #include <iterator> 23 23 #include <functional> 24 #include <vector> 24 25 25 26 #include <lemon/bits/utility.h> … … 240 241 typedef StdMap<Key, T1, C1> other; 241 242 }; 243 }; 244 245 /// \brief Map for storing values for the range \c [0..size1] range keys 246 /// 247 /// The current map has the \c [0..size1] keyset and the values 248 /// are stored in a \c std::vector<T> container. It can be used with 249 /// some data structures, for example \c UnionFind, \c BinHeap, when 250 /// the used items are small integer numbers. 251 template <typename T> 252 class IntegerMap { 253 254 template <typename T1> 255 friend class IntegerMap; 256 257 public: 258 259 typedef True ReferenceMapTag; 260 ///\e 261 typedef int Key; 262 ///\e 263 typedef T Value; 264 ///\e 265 typedef T& Reference; 266 ///\e 267 typedef const T& ConstReference; 268 269 private: 270 271 typedef std::vector<T> Vector; 272 Vector _vector; 273 274 public: 275 276 /// Constructor with specified default value 277 IntegerMap(int size = 0, const T& value = T()) : _vector(size, value) {} 278 279 /// \brief Constructs the map from an appropriate std::vector. 280 template <typename T1> 281 IntegerMap(const std::vector<T1>& vector) 282 : _vector(vector.begin(), vector.end()) {} 283 284 /// \brief Constructs a map from an other IntegerMap. 285 template <typename T1> 286 IntegerMap(const IntegerMap<T1> &c) 287 : _vector(c._vector.begin(), c._vector.end()) {} 288 289 /// \brief Resize the container 290 void resize(int size, const T& value = T()) { 291 _vector.resize(size, value); 292 } 293 294 private: 295 296 IntegerMap& operator=(const IntegerMap&); 297 298 public: 299 300 ///\e 301 Reference operator[](Key k) { 302 return _vector[k]; 303 } 304 305 /// \e 306 ConstReference operator[](Key k) const { 307 return _vector[k]; 308 } 309 310 /// \e 311 void set(const Key &k, const T& t) { 312 _vector[k] = t; 313 } 314 242 315 }; 243 316
Note: See TracChangeset
for help on using the changeset viewer.