src/work/deba/map_utils.h
changeset 1133 9fd485470fee
parent 1115 444f69240539
     1.1 --- a/src/work/deba/map_utils.h	Sun Feb 06 20:14:30 2005 +0000
     1.2 +++ b/src/work/deba/map_utils.h	Mon Feb 07 10:48:14 2005 +0000
     1.3 @@ -23,16 +23,17 @@
     1.4  
     1.5  namespace lemon {
     1.6  
     1.7 -  /// \addtogroup gutils
     1.8 +  /// \addtogroup mutils
     1.9    /// @{
    1.10  
    1.11 -
    1.12    /// \brief General inversable map type.
    1.13  
    1.14    /// This type provides simple inversable map functions. 
    1.15    /// The InversableMap wraps an arbitrary ReadWriteMap 
    1.16    /// and if a key is setted to a new value then store it
    1.17    /// in the inverse map.
    1.18 +  /// \param _Graph The graph type.
    1.19 +  /// \param _Map The map to extend with inversable functionality. 
    1.20    template <
    1.21      typename _Graph, 
    1.22      typename _Map
    1.23 @@ -43,7 +44,9 @@
    1.24      typedef _Graph Graph;
    1.25  
    1.26      typedef _Map Map;
    1.27 +    /// The key type of InversableMap (Node, Edge, UndirEdge).
    1.28      typedef typename _Map::Key Key;
    1.29 +    /// The value type of the InversableMap.
    1.30      typedef typename _Map::Value Value;
    1.31      typedef std::map<Value, Key> InverseMap;
    1.32      
    1.33 @@ -60,38 +63,61 @@
    1.34      /// It sets the map and the inverse map to given key-value pair.
    1.35      void set(const Key& key, const Value& val) {
    1.36        Value oldval = Map::operator[](key);
    1.37 -      typename InverseMap::iterator it = inv_map.find(oldval);
    1.38 -      if (it != inv_map.end() && it->second == key) {
    1.39 -	inv_map.erase(it);
    1.40 +      typename InverseMap::iterator it = invMap.find(oldval);
    1.41 +      if (it != invMap.end() && it->second == key) {
    1.42 +	invMap.erase(it);
    1.43        }      
    1.44 -      inv_map.insert(make_pair(val, key));
    1.45 +      invMap.insert(make_pair(val, key));
    1.46        Map::set(key, val);
    1.47      }
    1.48  
    1.49 -    ConstReference operator[](const Key&) const {
    1.50 +    /// \brief The getter function of the map.
    1.51 +    ///
    1.52 +    /// It gives back the value associated with the key.
    1.53 +    ConstReference operator[](const Key& key) const {
    1.54        return Map::operator[](key);
    1.55      }
    1.56  
    1.57 -    virtual void add(const Key&) {
    1.58 +    /// \brief Add a new key to the map.
    1.59 +    ///
    1.60 +    /// Add a new key to the map. It is called by the
    1.61 +    /// \c AlterationNotifier.
    1.62 +    virtual void add(const Key& key) {
    1.63        Map::add(key);
    1.64      }
    1.65  
    1.66 -    virtual void erase(const Key&) {
    1.67 +    /// \brief Erase the key from the map.
    1.68 +    ///
    1.69 +    /// Erase the key to the map. It is called by the
    1.70 +    /// \c AlterationNotifier.
    1.71 +    virtual void erase(const Key& key) {
    1.72        Value val = Map::operator[](key);
    1.73 -      typename InverseMap::iterator it = inv_map.find(val);
    1.74 -      if (it != inv_map.end() && it->second == key) {
    1.75 +      typename InverseMap::iterator it = invMap.find(val);
    1.76 +      if (it != invMap.end() && it->second == key) {
    1.77  	invMap.erase(it);
    1.78        }
    1.79        Map::erase(key);
    1.80      }
    1.81  
    1.82 +    /// \brief Clear the keys from the map and inverse map.
    1.83 +    ///
    1.84 +    /// Clear the keys from the map and inverse map. It is called by the
    1.85 +    /// \c AlterationNotifier.
    1.86 +    virtual void clear() {
    1.87 +      invMap.clear();
    1.88 +      Map::clear();
    1.89 +    }
    1.90 +
    1.91 +    /// \brief It gives back the just readeable inverse map.
    1.92 +    ///
    1.93 +    /// It gives back the just readeable inverse map.
    1.94      const InverseMap& inverse() const {
    1.95 -      return inv_map;
    1.96 +      return invMap;
    1.97      } 
    1.98  
    1.99  
   1.100    private:
   1.101 -    InverseMap inv_map;    
   1.102 +    InverseMap invMap;    
   1.103    };
   1.104  
   1.105  
   1.106 @@ -135,29 +161,45 @@
   1.107        build();
   1.108      }
   1.109  
   1.110 +    /// \brief Add a new key to the map.
   1.111 +    ///
   1.112 +    /// Add a new key to the map. It is called by the
   1.113 +    /// \c AlterationNotifier.
   1.114      virtual void add(const Item& item) {
   1.115        Map::add(item);
   1.116 -      Map::set(item, inv_map.size());
   1.117 -      inv_map.push_back(item);
   1.118 +      Map::set(item, invMap.size());
   1.119 +      invMap.push_back(item);
   1.120      }
   1.121  
   1.122 +    /// \brief Erase the key from the map.
   1.123 +    ///
   1.124 +    /// Erase the key to the map. It is called by the
   1.125 +    /// \c AlterationNotifier.
   1.126      virtual void erase(const Item& item) {
   1.127 -      Map::set(inv_map.back(), Map::operator[](item));
   1.128 -      inv_map[Map::operator[](item)] = inv_map.back();
   1.129 +      Map::set(invMap.back(), Map::operator[](item));
   1.130 +      invMap[Map::operator[](item)] = invMap.back();
   1.131        Map::erase(item);
   1.132      }
   1.133  
   1.134 +    /// \brief Build the unique map.
   1.135 +    ///
   1.136 +    /// Build the unique map. It is called by the
   1.137 +    /// \c AlterationNotifier.
   1.138      virtual void build() {
   1.139        Map::build();
   1.140        Item it;
   1.141        for (getGraph()->first(it); it != INVALID; getGraph()->next(it)) {
   1.142 -	Map::set(it, inv_map.size());
   1.143 -	inv_map.push_back(it);	
   1.144 +	Map::set(it, invMap.size());
   1.145 +	invMap.push_back(it);	
   1.146        }      
   1.147      }
   1.148      
   1.149 +    /// \brief Clear the keys from the map.
   1.150 +    ///
   1.151 +    /// Clear the keys from the map. It is called by the
   1.152 +    /// \c AlterationNotifier.
   1.153      virtual void clear() {
   1.154 -      inv_map.clear();
   1.155 +      invMap.clear();
   1.156        Map::clear();
   1.157      }
   1.158  
   1.159 @@ -172,11 +214,11 @@
   1.160      ///
   1.161      /// Gives back the inverse of the map.
   1.162      const InverseMap inverse() const {
   1.163 -      return inv_map;
   1.164 +      return invMap;
   1.165      }
   1.166  
   1.167    private:
   1.168 -    vector<Item> inv_map;
   1.169 +    vector<Item> invMap;
   1.170    };
   1.171    
   1.172    /// Provides an immutable and unique id for each item in the graph.