diff -r bb523a4758f7 -r a99186a9b6b0 lemon/maps.h --- a/lemon/maps.h Wed Nov 14 15:36:37 2007 +0000 +++ b/lemon/maps.h Wed Nov 14 17:42:48 2007 +0000 @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -241,6 +242,78 @@ }; }; + /// \brief Map for storing values for the range \c [0..size-1] range keys + /// + /// The current map has the \c [0..size-1] keyset and the values + /// are stored in a \c std::vector container. It can be used with + /// some data structures, for example \c UnionFind, \c BinHeap, when + /// the used items are small integer numbers. + template + class IntegerMap { + + template + friend class IntegerMap; + + public: + + typedef True ReferenceMapTag; + ///\e + typedef int Key; + ///\e + typedef T Value; + ///\e + typedef T& Reference; + ///\e + typedef const T& ConstReference; + + private: + + typedef std::vector Vector; + Vector _vector; + + public: + + /// Constructor with specified default value + IntegerMap(int size = 0, const T& value = T()) : _vector(size, value) {} + + /// \brief Constructs the map from an appropriate std::vector. + template + IntegerMap(const std::vector& vector) + : _vector(vector.begin(), vector.end()) {} + + /// \brief Constructs a map from an other IntegerMap. + template + IntegerMap(const IntegerMap &c) + : _vector(c._vector.begin(), c._vector.end()) {} + + /// \brief Resize the container + void resize(int size, const T& value = T()) { + _vector.resize(size, value); + } + + private: + + IntegerMap& operator=(const IntegerMap&); + + public: + + ///\e + Reference operator[](Key k) { + return _vector[k]; + } + + /// \e + ConstReference operator[](Key k) const { + return _vector[k]; + } + + /// \e + void set(const Key &k, const T& t) { + _vector[k] = t; + } + + }; + /// @} /// \addtogroup map_adaptors