[Lemon-commits] deba: r3117 - hugo/trunk/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Dec 18 15:35:34 CET 2006


Author: deba
Date: Mon Dec 18 15:35:33 2006
New Revision: 3117

Modified:
   hugo/trunk/lemon/graph_utils.h

Log:
Easier inverse than m.inverse()[a] => m(a)



Modified: hugo/trunk/lemon/graph_utils.h
==============================================================================
--- hugo/trunk/lemon/graph_utils.h	(original)
+++ hugo/trunk/lemon/graph_utils.h	Mon Dec 18 15:35:33 2006
@@ -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:



More information about the Lemon-commits mailing list