[Lemon-commits] Balazs Dezso: Use member variables to store the ...

Lemon HG hg at lemon.cs.elte.hu
Fri Mar 1 17:49:47 CET 2013


details:   http://lemon.cs.elte.hu/hg/lemon/rev/939ee6d1e525
changeset: 1191:939ee6d1e525
user:      Balazs Dezso <deba [at] inf.elte.hu>
date:      Tue Nov 16 08:19:11 2010 +0100
description:
	Use member variables to store the highest IDs in bipartite
	partitions (#69)

diffstat:

 lemon/smart_graph.h |  44 +++++++++++++++++++++-----------------------
 1 files changed, 21 insertions(+), 23 deletions(-)

diffs (102 lines):

diff --git a/lemon/smart_graph.h b/lemon/smart_graph.h
--- a/lemon/smart_graph.h
+++ b/lemon/smart_graph.h
@@ -829,6 +829,7 @@
     std::vector<ArcT> arcs;
 
     int first_red, first_blue;
+    int max_red, max_blue;
 
   public:
 
@@ -890,29 +891,22 @@
 
 
     SmartBpGraphBase()
-      : nodes(), arcs(), first_red(-1), first_blue(-1) {}
+      : nodes(), arcs(), first_red(-1), first_blue(-1),
+        max_red(-1), max_blue(-1) {}
 
     typedef True NodeNumTag;
     typedef True EdgeNumTag;
     typedef True ArcNumTag;
 
     int nodeNum() const { return nodes.size(); }
-    int redNum() const {
-      return first_red == -1 ? 0 : nodes[first_red].partition_index + 1;
-    }
-    int blueNum() const {
-      return first_blue == -1 ? 0 : nodes[first_blue].partition_index + 1;
-    }
+    int redNum() const { return max_red + 1; }
+    int blueNum() const { return max_blue + 1; }
     int edgeNum() const { return arcs.size() / 2; }
     int arcNum() const { return arcs.size(); }
 
     int maxNodeId() const { return nodes.size()-1; }
-    int maxRedId() const {
-      return first_red == -1 ? -1 : nodes[first_red].partition_index;
-    }
-    int maxBlueId() const {
-      return first_blue == -1 ? -1 : nodes[first_blue].partition_index;
-    }
+    int maxRedId() const { return max_red; }
+    int maxBlueId() const { return max_blue; }
     int maxEdgeId() const { return arcs.size() / 2 - 1; }
     int maxArcId() const { return arcs.size()-1; }
 
@@ -1041,11 +1035,7 @@
       nodes.push_back(NodeT());
       nodes[n].first_out = -1;
       nodes[n].red = true;
-      if (first_red == -1) {
-        nodes[n].partition_index = 0;
-      } else {
-        nodes[n].partition_index = nodes[first_red].partition_index + 1;
-      }
+      nodes[n].partition_index = ++max_red;
       nodes[n].partition_next = first_red;
       first_red = n;
 
@@ -1057,11 +1047,7 @@
       nodes.push_back(NodeT());
       nodes[n].first_out = -1;
       nodes[n].red = false;
-      if (first_blue == -1) {
-        nodes[n].partition_index = 0;
-      } else {
-        nodes[n].partition_index = nodes[first_blue].partition_index + 1;
-      }
+      nodes[n].partition_index = ++max_blue;
       nodes[n].partition_next = first_blue;
       first_blue = n;
 
@@ -1090,6 +1076,8 @@
       nodes.clear();
       first_red = -1;
       first_blue = -1;
+      max_blue = -1;
+      max_red = -1;
     }
 
   };
@@ -1244,9 +1232,19 @@
         Node node = nodeFromId(n);
         if (Parent::red(node)) {
           first_red = nodes[n].partition_next;
+          if (first_red != -1) {
+            max_red = nodes[first_red].partition_index;
+          } else {
+            max_red = -1;
+          }
           Parent::notifier(RedNode()).erase(node);          
         } else {
           first_blue = nodes[n].partition_next;
+          if (first_blue != -1) {
+            max_blue = nodes[first_blue].partition_index;
+          } else {
+            max_blue = -1;
+          }
           Parent::notifier(BlueNode()).erase(node);
         }
         Parent::notifier(Node()).erase(node);



More information about the Lemon-commits mailing list