Code

minor performance improvement
authortgdwyer <tgdwyer@users.sourceforge.net>
Mon, 17 Jul 2006 05:35:08 +0000 (05:35 +0000)
committertgdwyer <tgdwyer@users.sourceforge.net>
Mon, 17 Jul 2006 05:35:08 +0000 (05:35 +0000)
src/libcola/connected_components.cpp
src/libvpsc/remove_rectangle_overlap.h

index 7e72d46a786086b992f43f46e05739ddb97bef60..0cf6ee45a2bb90f14766ce5820339eb7a87cc57c 100644 (file)
@@ -1,6 +1,7 @@
 #include <map>
-#include "cola.h"
+#include <list>
 #include <libvpsc/remove_rectangle_overlap.h>
+#include "cola.h"
 using namespace std;
 
 namespace cola {
@@ -34,15 +35,16 @@ namespace cola {
             unsigned id;
             bool visited;
             vector<Node*> neighbours;
+            list<Node*>::iterator listPos;
             Rectangle* r;
         };
         // Depth first search traversal of graph to find connected component
         void dfs(Node* v,
-                set<Node*>& remaining,
+                list<Node*>& remaining,
                 Component* component,
                 map<unsigned,pair<Component*,unsigned> > &cmap) {
             v->visited=true;
-            remaining.erase(v);
+            remaining.erase(v->listPos);
             cmap[v->id]=make_pair(component,component->node_ids.size());
             component->node_ids.push_back(v->id);
             component->rects.push_back(v->r);
@@ -66,12 +68,12 @@ namespace cola {
             vector<Component*> &components) {
         unsigned n=rs.size();
         vector<Node> vs(n);
-        set<Node*> remaining;
+        list<Node*> remaining;
         for(unsigned i=0;i<n;i++) {
             vs[i].id=i;
             vs[i].visited=false;
             vs[i].r=rs[i];
-            remaining.insert(&vs[i]);
+            vs[i].listPos = remaining.insert(remaining.end(),&vs[i]);
         }
         vector<Edge>::const_iterator ei;
         SimpleConstraints::const_iterator ci;
index 82f3ef4948e6cd123efefb93b500c1ae7a06a663..baa15b5945a70ca9111c04476a3cc3434c9d6ec3 100644 (file)
@@ -12,8 +12,9 @@
  *
  * Released under GNU LGPL.  Read the file 'COPYING' for more information.
  */
-
-class vpsc::Rectangle;
+namespace vpsc { 
+       class Rectangle;
+}
 
 void removeRectangleOverlap(unsigned n, vpsc::Rectangle *rs[], double xBorder, double yBorder);