]> granicus.if.org Git - graphviz/commitdiff
use empty() to check size() against 0 in VPSC
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 21 Nov 2020 01:20:28 +0000 (17:20 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 23 Jan 2021 18:29:33 +0000 (10:29 -0800)
This is significantly faster for large vectors.

lib/vpsc/blocks.cpp
lib/vpsc/solve_VPSC.cpp

index 5603f3f4bff6fc92e1c112daa5d2fbc04344d7d0..dedfdf9f55a9b6fe62b59f1016b0a4ccbfa8a108 100644 (file)
@@ -60,7 +60,7 @@ list<Variable*> *Blocks::totalOrder() {
                vs[i]->visited=false;
        }
        for(int i=0;i<nvs;i++) {
-               if(vs[i]->in.size()==0) {
+               if(vs[i]->in.empty()) {
                        dfsVisit(vs[i],order);
                }
        }
index 4f8f65fa759250640e2452d0457cee9f506a397e..cb1328ef7eeb15dfde8633291177bcc5bf9aca1e 100644 (file)
@@ -336,16 +336,16 @@ bool VPSC::constraintGraphIsCyclic(const unsigned n, Variable *vs[]) {
                        varmap[vs[i]]->out.insert(varmap[r]);
                }
        }
-       while(graph.size()>0) {
+       while(!graph.empty()) {
                node *u=NULL;
                vector<node*>::iterator i=graph.begin();
                for(;i!=graph.end();i++) {
                        u=*i;
-                       if(u->in.size()==0) {
+                       if(u->in.empty()) {
                                break;
                        }
                }
-               if(i==graph.end() && graph.size()>0) {
+               if(i==graph.end() && !graph.empty()) {
                        //cycle found!
                        return true;
                } else {
@@ -393,16 +393,16 @@ bool VPSC::blockGraphIsCyclic() {
                        c=b->findMinOutConstraint();
                }
        }
-       while(graph.size()>0) {
+       while(!graph.empty()) {
                node *u=NULL;
                vector<node*>::iterator i=graph.begin();
                for(;i!=graph.end();i++) {
                        u=*i;
-                       if(u->in.size()==0) {
+                       if(u->in.empty()) {
                                break;
                        }
                }
-               if(i==graph.end() && graph.size()>0) {
+               if(i==graph.end() && !graph.empty()) {
                        //cycle found!
                        return true;
                } else {