[Lemon-commits] deba: r3377 - lemon/trunk/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Wed Nov 14 18:42:48 CET 2007
Author: deba
Date: Wed Nov 14 18:42:48 2007
New Revision: 3377
Modified:
lemon/trunk/lemon/maps.h
Log:
IntegerMap
Modified: lemon/trunk/lemon/maps.h
==============================================================================
--- lemon/trunk/lemon/maps.h (original)
+++ lemon/trunk/lemon/maps.h Wed Nov 14 18:42:48 2007
@@ -21,6 +21,7 @@
#include <iterator>
#include <functional>
+#include <vector>
#include <lemon/bits/utility.h>
#include <lemon/bits/traits.h>
@@ -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<T> container. It can be used with
+ /// some data structures, for example \c UnionFind, \c BinHeap, when
+ /// the used items are small integer numbers.
+ template <typename T>
+ class IntegerMap {
+
+ template <typename T1>
+ 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<T> 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 <typename T1>
+ IntegerMap(const std::vector<T1>& vector)
+ : _vector(vector.begin(), vector.end()) {}
+
+ /// \brief Constructs a map from an other IntegerMap.
+ template <typename T1>
+ IntegerMap(const IntegerMap<T1> &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
More information about the Lemon-commits
mailing list