Easier inverse than m.inverse()[a] => m(a)
authordeba
Mon, 18 Dec 2006 14:35:33 +0000
changeset 2331e389580e3348
parent 2330 9dccb1abc721
child 2332 587531b4fe0e
Easier inverse than m.inverse()[a] => m(a)
lemon/graph_utils.h
     1.1 --- a/lemon/graph_utils.h	Mon Dec 18 10:12:07 2006 +0000
     1.2 +++ b/lemon/graph_utils.h	Mon Dec 18 14:35:33 2006 +0000
     1.3 @@ -1582,14 +1582,18 @@
     1.4  
     1.5      /// \brief Constructor.
     1.6      ///
     1.7 -    /// Constructor for creating id map.
     1.8 +    /// Constructor of the map.
     1.9      explicit IdMap(const Graph& _graph) : graph(&_graph) {}
    1.10  
    1.11      /// \brief Gives back the \e id of the item.
    1.12      ///
    1.13 -    /// Gives back the immutable and unique \e id of the map.
    1.14 +    /// Gives back the immutable and unique \e id of the item.
    1.15      int operator[](const Item& item) const { return graph->id(item);}
    1.16  
    1.17 +    /// \brief Gives back the item by its id.
    1.18 +    ///
    1.19 +    /// Gives back the item by its id.
    1.20 +    Item operator()(int id) { return graph->fromId(id, Item()); }
    1.21  
    1.22    private:
    1.23      const Graph* graph;
    1.24 @@ -1618,6 +1622,7 @@
    1.25        /// Gives back the given item from its id.
    1.26        /// 
    1.27        Item operator[](int id) const { return graph->fromId(id, Item());}
    1.28 +
    1.29      private:
    1.30        const Graph* graph;
    1.31      };
    1.32 @@ -1744,6 +1749,14 @@
    1.33        return Map::operator[](key);
    1.34      }
    1.35  
    1.36 +    /// \brief Gives back the item by its value.
    1.37 +    ///
    1.38 +    /// Gives back the item by its value.
    1.39 +    Key operator()(const Value& key) const {
    1.40 +      typename Container::const_iterator it = invMap.find(key);
    1.41 +      return it != invMap.end() ? it->second : INVALID;
    1.42 +    }
    1.43 +
    1.44    protected:
    1.45  
    1.46      /// \brief Erase the key from the map.
    1.47 @@ -1807,8 +1820,7 @@
    1.48        /// Subscript operator. It gives back always the item 
    1.49        /// what was last assigned to the value.
    1.50        Value operator[](const Key& key) const {
    1.51 -	typename Container::const_iterator it = inverted.invMap.find(key);
    1.52 -	return it->second;
    1.53 +	return inverted(key);
    1.54        }
    1.55        
    1.56      private:
    1.57 @@ -1966,6 +1978,13 @@
    1.58      int operator[](const Item& item) const {
    1.59        return Map::operator[](item);
    1.60      }
    1.61 +
    1.62 +    /// \brief Gives back the item by its descriptor.
    1.63 +    ///
    1.64 +    /// Gives back th item by its descriptor.
    1.65 +    Item operator()(int id) const {
    1.66 +      return invMap[id];
    1.67 +    }
    1.68      
    1.69    private:
    1.70  
    1.71 @@ -1995,14 +2014,14 @@
    1.72        /// Subscript operator. It gives back the item 
    1.73        /// that the descriptor belongs to currently.
    1.74        Value operator[](const Key& key) const {
    1.75 -	return inverted.invMap[key];
    1.76 +	return inverted(key);
    1.77        }
    1.78  
    1.79        /// \brief Size of the map.
    1.80        ///
    1.81        /// Returns the size of the map.
    1.82        unsigned int size() const {
    1.83 -	return inverted.invMap.size();
    1.84 +	return inverted.size();
    1.85        }
    1.86        
    1.87      private: