[Lemon-commits] [lemon_svn] deba: r2379 - hugo/trunk/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:52:13 CET 2006


Author: deba
Date: Wed Nov 23 16:42:36 2005
New Revision: 2379

Modified:
   hugo/trunk/lemon/graph_utils.h

Log:
Correcting alteration notifing



Modified: hugo/trunk/lemon/graph_utils.h
==============================================================================
--- hugo/trunk/lemon/graph_utils.h	(original)
+++ hugo/trunk/lemon/graph_utils.h	Wed Nov 23 16:42:36 2005
@@ -110,8 +110,7 @@
   // Node counting:
 
   template <typename Graph>
-  inline
-  typename enable_if<typename Graph::NodeNumTag, int>::type
+  inline typename enable_if<typename Graph::NodeNumTag, int>::type
   _countNodes(const Graph &g) {
     return g.nodeNum();
   }
@@ -137,8 +136,7 @@
   // Edge counting:
 
   template <typename Graph>
-  inline
-  typename enable_if<typename Graph::EdgeNumTag, int>::type
+  inline typename enable_if<typename Graph::EdgeNumTag, int>::type
   _countEdges(const Graph &g) {
     return g.edgeNum();
   }
@@ -420,7 +418,7 @@
     /// It increments the iterator and gives back the next edge.
     ConUndirEdgeIt& operator++() {
       Parent::operator=(findUndirEdge(graph, graph.source(*this), 
-				 graph.target(*this), *this));
+				      graph.target(*this), *this));
       return *this;
     }
   private:
@@ -938,14 +936,6 @@
 
   protected:
 
-    /// \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);
-    }
-
     /// \brief Erase the key from the map.
     ///
     /// Erase the key to the map. It is called by the
@@ -959,6 +949,21 @@
       Map::erase(key);
     }
 
+    /// \brief Erase more keys from the map.
+    ///
+    /// Erase more keys from the map. It is called by the
+    /// \c AlterationNotifier.
+    virtual void erase(const std::vector<Key>& keys) {
+      for (int i = 0; i < (int)keys.size(); ++i) {
+	Value val = Map::operator[](keys[i]);
+	typename Container::iterator it = invMap.find(val);
+	if (it != invMap.end() && it->second == keys[i]) {
+	  invMap.erase(it);
+	}
+      }
+      Map::erase(keys);
+    }
+
     /// \brief Clear the keys from the map and inverse map.
     ///
     /// Clear the keys from the map and inverse map. It is called by the
@@ -1070,9 +1075,21 @@
       invMap.push_back(item);
     }
 
+    /// \brief Add more new keys to the map.
+    ///
+    /// Add more new keys to the map. It is called by the
+    /// \c AlterationNotifier.
+    virtual void add(const std::vector<Item>& items) {
+      Map::add(items);
+      for (int i = 0; i < (int)items.size(); ++i) {
+	Map::set(items[i], invMap.size());
+	invMap.push_back(items[i]);
+      }
+    }
+
     /// \brief Erase the key from the map.
     ///
-    /// Erase the key to the map. It is called by the
+    /// Erase the key from the map. It is called by the
     /// \c AlterationNotifier.
     virtual void erase(const Item& item) {
       Map::set(invMap.back(), Map::operator[](item));
@@ -1081,6 +1098,19 @@
       Map::erase(item);
     }
 
+    /// \brief Erase more keys from the map.
+    ///
+    /// Erase more keys from the map. It is called by the
+    /// \c AlterationNotifier.
+    virtual void erase(const std::vector<Item>& items) {
+      for (int i = 0; i < (int)items.size(); ++i) {
+	Map::set(invMap.back(), Map::operator[](items[i]));
+	invMap[Map::operator[](items[i])] = invMap.back();
+	invMap.pop_back();
+      }
+      Map::erase(items);
+    }
+
     /// \brief Build the unique map.
     ///
     /// Build the unique map. It is called by the
@@ -1379,8 +1409,8 @@
   ///
   /// \warning Besides addNode() and addEdge(), a graph structure may provide
   /// alternative ways to modify the graph. The correct behavior of InDegMap
-  /// is not guarantied if these additional featureas are used. For example
-  /// the funstions \ref ListGraph::changeSource() "changeSource()",
+  /// is not guarantied if these additional features are used. For example
+  /// the functions \ref ListGraph::changeSource() "changeSource()",
   /// \ref ListGraph::changeTarget() "changeTarget()" and
   /// \ref ListGraph::reverseEdge() "reverseEdge()"
   /// of \ref ListGraph will \e not update the degree values correctly.
@@ -1409,10 +1439,16 @@
       
       AutoNodeMap(const Graph& graph) : Parent(graph, 0) {}
       
-      void add(const Key& key) {
+      virtual void add(const Key& key) {
 	Parent::add(key);
 	Parent::set(key, 0);
       }
+      virtual void add(const std::vector<Key>& keys) {
+	Parent::add(keys);
+	for (int i = 0; i < (int)keys.size(); ++i) {
+	  Parent::set(keys[i], 0);
+	}
+      }
     };
 
   public:
@@ -1451,14 +1487,6 @@
       --deg[graph.target(edge)];
     }
 
-    virtual void signalChange(const Edge& edge) {
-      erase(edge);
-    }
-
-    virtual void commitChange(const Edge& edge) {
-      add(edge);
-    }
-
     virtual void build() {
       for(typename _Graph::NodeIt it(graph); it != INVALID; ++it) {
 	deg[it] = countInEdges(graph, it);
@@ -1485,8 +1513,8 @@
   ///
   /// \warning Besides addNode() and addEdge(), a graph structure may provide
   /// alternative ways to modify the graph. The correct behavior of OutDegMap
-  /// is not guarantied if these additional featureas are used. For example
-  /// the funstions \ref ListGraph::changeSource() "changeSource()",
+  /// is not guarantied if these additional features are used. For example
+  /// the functions \ref ListGraph::changeSource() "changeSource()",
   /// \ref ListGraph::changeTarget() "changeTarget()" and
   /// \ref ListGraph::reverseEdge() "reverseEdge()"
   /// of \ref ListGraph will \e not update the degree values correctly.
@@ -1515,10 +1543,16 @@
       
       AutoNodeMap(const Graph& graph) : Parent(graph, 0) {}
       
-      void add(const Key& key) {
+      virtual void add(const Key& key) {
 	Parent::add(key);
 	Parent::set(key, 0);
       }
+      virtual void add(const std::vector<Key>& keys) {
+	Parent::add(keys);
+	for (int i = 0; i < (int)keys.size(); ++i) {
+	  Parent::set(keys[i], 0);
+	}
+      }
     };
 
   public:
@@ -1557,15 +1591,6 @@
       --deg[graph.source(edge)];
     }
 
-    virtual void signalChange(const Edge& edge) {
-      erase(edge);
-    }
-
-    virtual void commitChange(const Edge& edge) {
-      add(edge);
-    }
-
-
     virtual void build() {
       for(typename _Graph::NodeIt it(graph); it != INVALID; ++it) {
 	deg[it] = countOutEdges(graph, it);



More information about the Lemon-commits mailing list