[Lemon-commits] Peter Kovacs: Improvements for iterable maps (#73)
Lemon HG
hg at lemon.cs.elte.hu
Mon Aug 31 08:27:15 CEST 2009
details: http://lemon.cs.elte.hu/hg/lemon/rev/71939d63ae77
changeset: 747:71939d63ae77
user: Peter Kovacs <kpeter [at] inf.elte.hu>
date: Tue Jul 21 22:43:31 2009 +0200
description:
Improvements for iterable maps (#73)
diffstat:
lemon/maps.h | 241 +++++++++++++++++++++++++-----------------------
test/maps_test.cc | 13 +-
2 files changed, 132 insertions(+), 122 deletions(-)
diffs (truncated from 600 to 300 lines):
diff --git a/lemon/maps.h b/lemon/maps.h
--- a/lemon/maps.h
+++ b/lemon/maps.h
@@ -22,16 +22,14 @@
#include <iterator>
#include <functional>
#include <vector>
+#include <map>
#include <lemon/core.h>
-#include <lemon/smart_graph.h>
///\file
///\ingroup maps
///\brief Miscellaneous property maps
-#include <map>
-
namespace lemon {
/// \addtogroup maps
@@ -1906,10 +1904,12 @@
/// It wraps an arbitrary \ref concepts::ReadWriteMap "ReadWriteMap"
/// and if a key is set to a new value then store it
/// in the inverse map.
- ///
/// The values of the map can be accessed
/// with stl compatible forward iterator.
///
+ /// This type is not reference map, so it cannot be modified with
+ /// the subscription operator.
+ ///
/// \tparam GR The graph type.
/// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
/// \c GR::Edge).
@@ -2312,34 +2312,41 @@
}
};
- /// \brief Dynamic iterable bool map.
+ /// \brief Dynamic iterable \c bool map.
///
- /// This class provides a special graph map type which can store for
- /// each graph item(node, arc, edge, etc.) a bool value. For both
- /// the true and the false values it is possible to iterate on the
- /// keys.
+ /// This class provides a special graph map type which can store a
+ /// \c bool value for graph items (\c Node, \c Arc or \c Edge).
+ /// For both \c true and \c false values it is possible to iterate on
+ /// the keys.
///
- /// \param GR The graph type.
- /// \param ITEM One of the graph's item types, the key of the map.
- template <typename GR, typename ITEM>
+ /// This type is a reference map, so it can be modified with the
+ /// subscription operator.
+ ///
+ /// \tparam GR The graph type.
+ /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
+ /// \c GR::Edge).
+ ///
+ /// \see IterableIntMap, IterableValueMap
+ /// \see CrossRefMap
+ template <typename GR, typename K>
class IterableBoolMap
- : protected ItemSetTraits<GR, ITEM>::template Map<int>::Type {
+ : protected ItemSetTraits<GR, K>::template Map<int>::Type {
private:
typedef GR Graph;
- typedef typename ItemSetTraits<Graph, ITEM>::ItemIt KeyIt;
- typedef typename ItemSetTraits<GR, ITEM>::template Map<int>::Type Parent;
+ typedef typename ItemSetTraits<GR, K>::ItemIt KeyIt;
+ typedef typename ItemSetTraits<GR, K>::template Map<int>::Type Parent;
- std::vector<ITEM> _array;
+ std::vector<K> _array;
int _sep;
public:
- /// Indicates that the map if reference map.
+ /// Indicates that the map is reference map.
typedef True ReferenceMapTag;
/// The key type
- typedef ITEM Key;
+ typedef K Key;
/// The value type
typedef bool Value;
/// The const reference type.
@@ -2353,10 +2360,10 @@
public:
- /// \brief Refernce to the value of the map.
+ /// \brief Reference to the value of the map.
///
- /// This class is similar to the bool type. It can be converted to
- /// bool and it provides the same operators.
+ /// This class is similar to the \c bool type. It can be converted to
+ /// \c bool and it provides the same operators.
class Reference {
friend class IterableBoolMap;
private:
@@ -2454,26 +2461,26 @@
_sep = (value ? _array.size() : 0);
}
- /// \brief Returns the number of the keys mapped to true.
+ /// \brief Returns the number of the keys mapped to \c true.
///
- /// Returns the number of the keys mapped to true.
+ /// Returns the number of the keys mapped to \c true.
int trueNum() const {
return _sep;
}
- /// \brief Returns the number of the keys mapped to false.
+ /// \brief Returns the number of the keys mapped to \c false.
///
- /// Returns the number of the keys mapped to false.
+ /// Returns the number of the keys mapped to \c false.
int falseNum() const {
return _array.size() - _sep;
}
- /// \brief Iterator for the keys mapped to true.
+ /// \brief Iterator for the keys mapped to \c true.
///
- /// Iterator for the keys mapped to true. It works
- /// like a graph item iterator in the map, it can be converted
+ /// Iterator for the keys mapped to \c true. It works
+ /// like a graph item iterator, it can be converted to
/// the key type of the map, incremented with \c ++ operator, and
- /// if the iterator leave the last valid key it will be equal to
+ /// if the iterator leaves the last valid key, it will be equal to
/// \c INVALID.
class TrueIt : public Key {
public:
@@ -2482,38 +2489,37 @@
/// \brief Creates an iterator.
///
/// Creates an iterator. It iterates on the
- /// keys which mapped to true.
- /// \param map The IterableIntMap
+ /// keys mapped to \c true.
+ /// \param map The IterableBoolMap.
explicit TrueIt(const IterableBoolMap& map)
: Parent(map._sep > 0 ? map._array[map._sep - 1] : INVALID),
_map(&map) {}
/// \brief Invalid constructor \& conversion.
///
- /// This constructor initializes the key to be invalid.
+ /// This constructor initializes the iterator to be invalid.
/// \sa Invalid for more details.
TrueIt(Invalid) : Parent(INVALID), _map(0) {}
/// \brief Increment operator.
///
- /// Increment Operator.
+ /// Increment operator.
TrueIt& operator++() {
int pos = _map->position(*this);
Parent::operator=(pos > 0 ? _map->_array[pos - 1] : INVALID);
return *this;
}
-
private:
const IterableBoolMap* _map;
};
- /// \brief Iterator for the keys mapped to false.
+ /// \brief Iterator for the keys mapped to \c false.
///
- /// Iterator for the keys mapped to false. It works
- /// like a graph item iterator in the map, it can be converted
+ /// Iterator for the keys mapped to \c false. It works
+ /// like a graph item iterator, it can be converted to
/// the key type of the map, incremented with \c ++ operator, and
- /// if the iterator leave the last valid key it will be equal to
+ /// if the iterator leaves the last valid key, it will be equal to
/// \c INVALID.
class FalseIt : public Key {
public:
@@ -2522,21 +2528,21 @@
/// \brief Creates an iterator.
///
/// Creates an iterator. It iterates on the
- /// keys which mapped to false.
- /// \param map The IterableIntMap
+ /// keys mapped to \c false.
+ /// \param map The IterableBoolMap.
explicit FalseIt(const IterableBoolMap& map)
: Parent(map._sep < int(map._array.size()) ?
map._array.back() : INVALID), _map(&map) {}
/// \brief Invalid constructor \& conversion.
///
- /// This constructor initializes the key to be invalid.
+ /// This constructor initializes the iterator to be invalid.
/// \sa Invalid for more details.
FalseIt(Invalid) : Parent(INVALID), _map(0) {}
/// \brief Increment operator.
///
- /// Increment Operator.
+ /// Increment operator.
FalseIt& operator++() {
int pos = _map->position(*this);
Parent::operator=(pos > _map->_sep ? _map->_array[pos - 1] : INVALID);
@@ -2550,20 +2556,20 @@
/// \brief Iterator for the keys mapped to a given value.
///
/// Iterator for the keys mapped to a given value. It works
- /// like a graph item iterator in the map, it can be converted
+ /// like a graph item iterator, it can be converted to
/// the key type of the map, incremented with \c ++ operator, and
- /// if the iterator leave the last valid key it will be equal to
+ /// if the iterator leaves the last valid key, it will be equal to
/// \c INVALID.
class ItemIt : public Key {
public:
typedef Key Parent;
- /// \brief Creates an iterator.
+ /// \brief Creates an iterator with a value.
///
- /// Creates an iterator. It iterates on the
- /// keys which mapped to false.
- /// \param map The IterableIntMap
- /// \param value Which elements should be iterated.
+ /// Creates an iterator with a value. It iterates on the
+ /// keys mapped to the given value.
+ /// \param map The IterableBoolMap.
+ /// \param value The value.
ItemIt(const IterableBoolMap& map, bool value)
: Parent(value ?
(map._sep > 0 ?
@@ -2573,13 +2579,13 @@
/// \brief Invalid constructor \& conversion.
///
- /// This constructor initializes the key to be invalid.
+ /// This constructor initializes the iterator to be invalid.
/// \sa Invalid for more details.
ItemIt(Invalid) : Parent(INVALID), _map(0) {}
/// \brief Increment operator.
///
- /// Increment Operator.
+ /// Increment operator.
ItemIt& operator++() {
int pos = _map->position(*this);
int _sep = pos >= _map->_sep ? _map->_sep : 0;
@@ -2673,30 +2679,35 @@
};
}
- ///\ingroup graph_maps
- ///
/// \brief Dynamic iterable integer map.
///
- /// This class provides a special graph map type which can store
- /// for each graph item(node, edge, etc.) an integer value. For each
- /// non negative value it is possible to iterate on the keys which
- /// mapped to the given value.
+ /// This class provides a special graph map type which can store an
+ /// integer value for graph items (\c Node, \c Arc or \c Edge).
+ /// For each non-negative value it is possible to iterate on the keys
+ /// mapped to the value.
///
- /// \note The size of the data structure depends on the highest
+ /// This type is a reference map, so it can be modified with the
+ /// subscription operator.
+ ///
+ /// \note The size of the data structure depends on the largest
/// value in the map.
///
- /// \param GR The graph type.
- /// \param ITEM One of the graph's item type, the key of the map.
- template <typename GR, typename ITEM>
+ /// \tparam GR The graph type.
+ /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
+ /// \c GR::Edge).
+ ///
+ /// \see IterableBoolMap, IterableValueMap
+ /// \see CrossRefMap
+ template <typename GR, typename K>
class IterableIntMap
- : protected ItemSetTraits<GR, ITEM>::
- template Map<_maps_bits::IterableIntMapNode<ITEM> >::Type {
+ : protected ItemSetTraits<GR, K>::
+ template Map<_maps_bits::IterableIntMapNode<K> >::Type {
public:
- typedef typename ItemSetTraits<GR, ITEM>::
- template Map<_maps_bits::IterableIntMapNode<ITEM> >::Type Parent;
+ typedef typename ItemSetTraits<GR, K>::
More information about the Lemon-commits
mailing list