# HG changeset patch # User deba # Date 1166452533 0 # Node ID e389580e334896db7006e4d2be94c1c74c22acea # Parent 9dccb1abc721b4d364ebc472ad20ccc9cfe991d3 Easier inverse than m.inverse()[a] => m(a) diff -r 9dccb1abc721 -r e389580e3348 lemon/graph_utils.h --- a/lemon/graph_utils.h Mon Dec 18 10:12:07 2006 +0000 +++ b/lemon/graph_utils.h Mon Dec 18 14:35:33 2006 +0000 @@ -1582,14 +1582,18 @@ /// \brief Constructor. /// - /// Constructor for creating id map. + /// Constructor of the map. explicit IdMap(const Graph& _graph) : graph(&_graph) {} /// \brief Gives back the \e id of the item. /// - /// Gives back the immutable and unique \e id of the map. + /// Gives back the immutable and unique \e id of the item. int operator[](const Item& item) const { return graph->id(item);} + /// \brief Gives back the item by its id. + /// + /// Gives back the item by its id. + Item operator()(int id) { return graph->fromId(id, Item()); } private: const Graph* graph; @@ -1618,6 +1622,7 @@ /// Gives back the given item from its id. /// Item operator[](int id) const { return graph->fromId(id, Item());} + private: const Graph* graph; }; @@ -1744,6 +1749,14 @@ return Map::operator[](key); } + /// \brief Gives back the item by its value. + /// + /// Gives back the item by its value. + Key operator()(const Value& key) const { + typename Container::const_iterator it = invMap.find(key); + return it != invMap.end() ? it->second : INVALID; + } + protected: /// \brief Erase the key from the map. @@ -1807,8 +1820,7 @@ /// Subscript operator. It gives back always the item /// what was last assigned to the value. Value operator[](const Key& key) const { - typename Container::const_iterator it = inverted.invMap.find(key); - return it->second; + return inverted(key); } private: @@ -1966,6 +1978,13 @@ int operator[](const Item& item) const { return Map::operator[](item); } + + /// \brief Gives back the item by its descriptor. + /// + /// Gives back th item by its descriptor. + Item operator()(int id) const { + return invMap[id]; + } private: @@ -1995,14 +2014,14 @@ /// Subscript operator. It gives back the item /// that the descriptor belongs to currently. Value operator[](const Key& key) const { - return inverted.invMap[key]; + return inverted(key); } /// \brief Size of the map. /// /// Returns the size of the map. unsigned int size() const { - return inverted.invMap.size(); + return inverted.size(); } private: