diff -r ab5c81fcc31a -r 9fd485470fee src/work/deba/map_utils.h --- a/src/work/deba/map_utils.h Sun Feb 06 20:14:30 2005 +0000 +++ b/src/work/deba/map_utils.h Mon Feb 07 10:48:14 2005 +0000 @@ -23,16 +23,17 @@ namespace lemon { - /// \addtogroup gutils + /// \addtogroup mutils /// @{ - /// \brief General inversable map type. /// This type provides simple inversable map functions. /// The InversableMap wraps an arbitrary ReadWriteMap /// and if a key is setted to a new value then store it /// in the inverse map. + /// \param _Graph The graph type. + /// \param _Map The map to extend with inversable functionality. template < typename _Graph, typename _Map @@ -43,7 +44,9 @@ typedef _Graph Graph; typedef _Map Map; + /// The key type of InversableMap (Node, Edge, UndirEdge). typedef typename _Map::Key Key; + /// The value type of the InversableMap. typedef typename _Map::Value Value; typedef std::map InverseMap; @@ -60,38 +63,61 @@ /// It sets the map and the inverse map to given key-value pair. void set(const Key& key, const Value& val) { Value oldval = Map::operator[](key); - typename InverseMap::iterator it = inv_map.find(oldval); - if (it != inv_map.end() && it->second == key) { - inv_map.erase(it); + typename InverseMap::iterator it = invMap.find(oldval); + if (it != invMap.end() && it->second == key) { + invMap.erase(it); } - inv_map.insert(make_pair(val, key)); + invMap.insert(make_pair(val, key)); Map::set(key, val); } - ConstReference operator[](const Key&) const { + /// \brief The getter function of the map. + /// + /// It gives back the value associated with the key. + ConstReference operator[](const Key& key) const { return Map::operator[](key); } - virtual void add(const Key&) { + /// \brief Add a new key to the map. + /// + /// Add a new key to the map. It is called by the + /// \c AlterationNotifier. + virtual void add(const Key& key) { Map::add(key); } - virtual void erase(const Key&) { + /// \brief Erase the key from the map. + /// + /// Erase the key to the map. It is called by the + /// \c AlterationNotifier. + virtual void erase(const Key& key) { Value val = Map::operator[](key); - typename InverseMap::iterator it = inv_map.find(val); - if (it != inv_map.end() && it->second == key) { + typename InverseMap::iterator it = invMap.find(val); + if (it != invMap.end() && it->second == key) { invMap.erase(it); } Map::erase(key); } + /// \brief Clear the keys from the map and inverse map. + /// + /// Clear the keys from the map and inverse map. It is called by the + /// \c AlterationNotifier. + virtual void clear() { + invMap.clear(); + Map::clear(); + } + + /// \brief It gives back the just readeable inverse map. + /// + /// It gives back the just readeable inverse map. const InverseMap& inverse() const { - return inv_map; + return invMap; } private: - InverseMap inv_map; + InverseMap invMap; }; @@ -135,29 +161,45 @@ build(); } + /// \brief Add a new key to the map. + /// + /// Add a new key to the map. It is called by the + /// \c AlterationNotifier. virtual void add(const Item& item) { Map::add(item); - Map::set(item, inv_map.size()); - inv_map.push_back(item); + Map::set(item, invMap.size()); + invMap.push_back(item); } + /// \brief Erase the key from the map. + /// + /// Erase the key to the map. It is called by the + /// \c AlterationNotifier. virtual void erase(const Item& item) { - Map::set(inv_map.back(), Map::operator[](item)); - inv_map[Map::operator[](item)] = inv_map.back(); + Map::set(invMap.back(), Map::operator[](item)); + invMap[Map::operator[](item)] = invMap.back(); Map::erase(item); } + /// \brief Build the unique map. + /// + /// Build the unique map. It is called by the + /// \c AlterationNotifier. virtual void build() { Map::build(); Item it; for (getGraph()->first(it); it != INVALID; getGraph()->next(it)) { - Map::set(it, inv_map.size()); - inv_map.push_back(it); + Map::set(it, invMap.size()); + invMap.push_back(it); } } + /// \brief Clear the keys from the map. + /// + /// Clear the keys from the map. It is called by the + /// \c AlterationNotifier. virtual void clear() { - inv_map.clear(); + invMap.clear(); Map::clear(); } @@ -172,11 +214,11 @@ /// /// Gives back the inverse of the map. const InverseMap inverse() const { - return inv_map; + return invMap; } private: - vector inv_map; + vector invMap; }; /// Provides an immutable and unique id for each item in the graph.