]> granicus.if.org Git - graphviz/commitdiff
replace vpsc uses of NULL with more modern nullptr
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 18 Apr 2021 20:17:00 +0000 (13:17 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 24 Apr 2021 21:15:10 +0000 (14:15 -0700)
lib/vpsc/block.cpp
lib/vpsc/block.h
lib/vpsc/blocks.cpp
lib/vpsc/csolve_VPSC.cpp
lib/vpsc/generate-constraints.cpp
lib/vpsc/pairingheap/PairingHeap.cpp
lib/vpsc/pairingheap/PairingHeap.h
lib/vpsc/solve_VPSC.cpp

index bc8da3956b600b22259e3b34c3b03dcf1513e45a..2b5ab1ade46002732b05fd5f9523ae99889a3ac5 100644 (file)
@@ -42,11 +42,11 @@ void Block::addVariable(Variable *v) {
 Block::Block(Variable *v) {
        timeStamp=0;
        posn=weight=wposn=0;
-       in=NULL;
-       out=NULL;
+       in=nullptr;
+       out=nullptr;
        deleted=false;
        vars=new vector<Variable*>;
-       if(v!=NULL) {
+       if(v!=nullptr) {
                v->offset=0;
                addVariable(v);
        }
@@ -149,7 +149,7 @@ void Block::mergeOut(Block *b) {
        out->merge(b->out);
 }
 Constraint *Block::findMinInConstraint() {
-       Constraint *v = NULL;
+       Constraint *v = nullptr;
        vector<Constraint*> outOfDate;
        while (!in->isEmpty()) {
                v = in->findMin();
@@ -192,18 +192,18 @@ Constraint *Block::findMinInConstraint() {
                in->insert(v);
        }
        if(in->isEmpty()) {
-               v=NULL;
+               v=nullptr;
        } else {
                v=in->findMin();
        }
        return v;
 }
 Constraint *Block::findMinOutConstraint() {
-       if(out->isEmpty()) return NULL;
+       if(out->isEmpty()) return nullptr;
        Constraint *v = out->findMin();
        while (v->left->block == v->right->block) {
                out->deleteMin();
-               if(out->isEmpty()) return NULL;
+               if(out->isEmpty()) return nullptr;
                v = out->findMin();
        }
        return v;
@@ -237,14 +237,14 @@ double Block::compute_dfdv(Variable *v, Variable *u, Constraint *&min_lm) {
                Constraint *c=*it;
                if(canFollowRight(c,u)) {
                        dfdv+=c->lm=compute_dfdv(c->right,v,min_lm);
-                       if(min_lm==NULL||c->lm<min_lm->lm) min_lm=c;
+                       if(min_lm==nullptr||c->lm<min_lm->lm) min_lm=c;
                }
        }
        for(vector<Constraint*>::iterator it=v->in.begin();it!=v->in.end();it++) {
                Constraint *c=*it;
                if(canFollowLeft(c,u)) {
                        dfdv-=c->lm=-compute_dfdv(c->left,v,min_lm);
-                       if(min_lm==NULL||c->lm<min_lm->lm) min_lm=c;
+                       if(min_lm==nullptr||c->lm<min_lm->lm) min_lm=c;
                }
        }
        return dfdv;
@@ -255,18 +255,18 @@ double Block::compute_dfdv(Variable *v, Variable *u, Constraint *&min_lm) {
 // the constraint c to compute the lagrangian multiplier lm_c.
 // The top level v and r are variables between which we want to find the
 // constraint with the smallest lm.  
-// When we find r we pass NULL to subsequent recursive calls, 
-// thus r=NULL indicates constraints are not on the shortest path.
-// Similarly, m is initially NULL and is only assigned a value if the next
+// When we find r we pass nullptr to subsequent recursive calls, 
+// thus r=nullptr indicates constraints are not on the shortest path.
+// Similarly, m is initially nullptr and is only assigned a value if the next
 // variable to be visited is r or if a possible min constraint is returned from
-// a nested call (rather than NULL).
+// a nested call (rather than nullptr).
 // Then, the search for the m with minimum lm occurs as we return from
 // the recursion (checking only constraints traversed left-to-right 
 // in order to avoid creating any new violations).
 Block::Pair Block::compute_dfdv_between(Variable* r, Variable* v, Variable* u, 
                Direction dir = NONE, bool changedDirection = false) {
        double dfdv=v->weight*(v->position() - v->desiredPosition);
-       Constraint *m=NULL;
+       Constraint *m=nullptr;
        for(Cit it(v->in.begin());it!=v->in.end();it++) {
                Constraint *c=*it;
                if(canFollowLeft(c,u)) {
@@ -274,7 +274,7 @@ Block::Pair Block::compute_dfdv_between(Variable* r, Variable* v, Variable* u,
                                changedDirection = true; 
                        }
                        if(c->left==r) {
-                               r=NULL; m=c; 
+                               r=nullptr; m=c; 
                        }
                        Pair p=compute_dfdv_between(r,c->left,v,
                                        LEFT,changedDirection);
@@ -290,7 +290,7 @@ Block::Pair Block::compute_dfdv_between(Variable* r, Variable* v, Variable* u,
                                changedDirection = true; 
                        }
                        if(c->right==r) {
-                               r=NULL; m=c; 
+                               r=nullptr; m=c; 
                        }
                        Pair p=compute_dfdv_between(r,c->right,v,
                                        RIGHT,changedDirection);
@@ -328,15 +328,15 @@ void Block::reset_active_lm(Variable *v, Variable *u) {
  * that most wants to split
  */
 Constraint *Block::findMinLM() {
-       Constraint *min_lm=NULL;
-       reset_active_lm(vars->front(),NULL);
-       compute_dfdv(vars->front(),NULL,min_lm);
+       Constraint *min_lm=nullptr;
+       reset_active_lm(vars->front(),nullptr);
+       compute_dfdv(vars->front(),nullptr,min_lm);
        return min_lm;
 }
 Constraint *Block::findMinLMBetween(Variable* lv, Variable* rv) {
-       Constraint *min_lm=NULL;
-       reset_active_lm(vars->front(),NULL);
-       min_lm=compute_dfdv_between(rv,lv,NULL).second;
+       Constraint *min_lm=nullptr;
+       reset_active_lm(vars->front(),nullptr);
+       min_lm=compute_dfdv_between(rv,lv,nullptr).second;
        return min_lm;
 }
 
index 196a3b689553b9bf7f6307bac98955886c6ea44b..8b969ba5afdeb198bb585bb4fe5c5ebd27254f51 100644 (file)
@@ -33,7 +33,7 @@ public:
        double posn;
        double weight;
        double wposn;
-       Block(Variable *v=NULL);
+       Block(Variable *v=nullptr);
        ~Block();
        Constraint* findMinLM();
        Constraint* findMinLMBetween(Variable* lv, Variable* rv);
index dedfdf9f55a9b6fe62b59f1016b0a4ccbfa8a108..a41a3e016c741cfac73f650c6976771a0dbe925b 100644 (file)
@@ -95,14 +95,14 @@ void Blocks::mergeLeft(Block *r) {
        r->timeStamp=++blockTimeCtr;
        r->setUpInConstraints();
        Constraint *c=r->findMinInConstraint();
-       while (c != NULL && c->slack()<0) {
+       while (c != nullptr && c->slack()<0) {
                if (RECTANGLE_OVERLAP_LOGGING) {
                        ofstream f(LOGFILE,ios::app);
                        f<<"mergeLeft on constraint: "<<*c<<"\n";
                }
                r->deleteMinInConstraint();
                Block *l = c->left->block;              
-               if (l->in==NULL) l->setUpInConstraints();
+               if (l->in==nullptr) l->setUpInConstraints();
                double dist = c->right->offset - c->left->offset - c->gap;
                if (r->vars->size() < l->vars->size()) {
                        dist=-dist;
@@ -130,7 +130,7 @@ void Blocks::mergeRight(Block *l) {
        }
        l->setUpOutConstraints();
        Constraint *c = l->findMinOutConstraint();
-       while (c != NULL && c->slack()<0) {             
+       while (c != nullptr && c->slack()<0) {          
                if (RECTANGLE_OVERLAP_LOGGING) {
                        ofstream f(LOGFILE,ios::app);
                        f<<"mergeRight on constraint: "<<*c<<"\n";
index 72b5c39130bcc9a2abf92eee6b47089b56d75431..36872cbd2363456a666bb9cafba7755aa508c2e7 100644 (file)
@@ -88,7 +88,7 @@ int getSplitCnt(IncVPSC *vpsc) {
        return vpsc->splitCnt;
 }
 void deleteVPSC(VPSC *vpsc) {
-       assert(vpsc!=NULL);
+       assert(vpsc!=nullptr);
        delete vpsc;
 }
 void solveVPSC(VPSC* vpsc) {
index da47b449cf184b2611ede69f0e92feb4f882aadc..4c598fbc264b2258a9ab6be185331f7b6c6730e3 100644 (file)
@@ -49,7 +49,7 @@ struct Node {
        Node *firstAbove, *firstBelow;
        NodeSet leftNeighbours, rightNeighbours;
        Node(Variable *v, Rectangle *r, double p) : v(v),r(r),pos(p) {
-               firstAbove=firstBelow=NULL;
+               firstAbove=firstBelow=nullptr;
                assert(r->width()<1e40);
        }
        void addLeftNeighbour(Node *u) {
@@ -189,12 +189,12 @@ int generateXConstraints(const int n, Rectangle** rs, Variable** vars, Constrain
                                }
                        } else {
                                Node *l=v->firstAbove, *r=v->firstBelow;
-                               if(l!=NULL) {
+                               if(l!=nullptr) {
                                        double sep = (v->r->width()+l->r->width())/2.0;
                                        constraints.push_back(new Constraint(l->v,v->v,sep));
                                        l->firstBelow=v->firstBelow;
                                }
-                               if(r!=NULL) {
+                               if(r!=nullptr) {
                                        double sep = (v->r->width()+r->r->width())/2.0;
                                        constraints.push_back(new Constraint(v->v,r->v,sep));
                                        r->firstAbove=v->firstAbove;
@@ -244,12 +244,12 @@ int generateYConstraints(const int n, Rectangle** rs, Variable** vars, Constrain
                } else {
                        // Close event
                        Node *l=v->firstAbove, *r=v->firstBelow;
-                       if(l!=NULL) {
+                       if(l!=nullptr) {
                                double sep = (v->r->height()+l->r->height())/2.0;
                                constraints.push_back(new Constraint(l->v,v->v,sep));
                                l->firstBelow=v->firstBelow;
                        }
-                       if(r!=NULL) {
+                       if(r!=nullptr) {
                                double sep = (v->r->height()+r->r->height())/2.0;
                                constraints.push_back(new Constraint(v->v,r->v,sep));
                                r->firstAbove=v->firstAbove;
index bbf020d7e4364e257a591c8d9bcac83ad5faf125..416981163d5ece487e131a2b0cadf730b20f4777 100644 (file)
@@ -36,7 +36,7 @@ using namespace std;
 template <class T>
 PairingHeap<T>::PairingHeap( bool (*lessThan)(T const &lhs, T const &rhs) )
 {
-       root = NULL;
+       root = nullptr;
        counter=0;
        this->lessThan=lessThan;
 }
@@ -48,7 +48,7 @@ PairingHeap<T>::PairingHeap( bool (*lessThan)(T const &lhs, T const &rhs) )
 template <class T>
 PairingHeap<T>::PairingHeap( const PairingHeap<T> & rhs )
 {
-       root = NULL;
+       root = nullptr;
        counter=rhs->size();
        *this = rhs;
 }
@@ -72,7 +72,7 @@ PairingHeap<T>::insert( const T & x )
 {
        PairNode<T> *newNode = new PairNode<T>( x );
 
-       if( root == NULL )
+       if( root == nullptr )
                root = newNode;
        else
                compareAndLink( root, newNode );
@@ -106,8 +106,8 @@ void PairingHeap<T>::deleteMin( )
 
     PairNode<T> *oldRoot = root;
 
-    if( root->leftChild == NULL )
-        root = NULL;
+    if( root->leftChild == nullptr )
+        root = nullptr;
     else
         root = combineSiblings( root->leftChild );
     counter--;
@@ -121,7 +121,7 @@ void PairingHeap<T>::deleteMin( )
 template <class T>
 bool PairingHeap<T>::isEmpty( ) const
 {
-       return root == NULL;
+       return root == nullptr;
 }
 
 /**
@@ -141,7 +141,7 @@ template <class T>
 void PairingHeap<T>::makeEmpty( )
 {
        reclaimMemory( root );
-       root = NULL;
+       root = nullptr;
 }
 
 /**
@@ -167,7 +167,7 @@ PairingHeap<T>::operator=( const PairingHeap<T> & rhs )
 template <class T>
 void PairingHeap<T>::reclaimMemory( PairNode<T> * t ) const
 {
-       if( t != NULL )
+       if( t != nullptr )
        {
                reclaimMemory( t->leftChild );
                reclaimMemory( t->nextSibling );
@@ -191,14 +191,14 @@ void PairingHeap<T>::decreaseKey( PairNode<T> *p,
        p->element = newVal;
        if( p != root )
        {
-               if( p->nextSibling != NULL )
+               if( p->nextSibling != nullptr )
                        p->nextSibling->prev = p->prev;
                if( p->prev->leftChild == p )
                        p->prev->leftChild = p->nextSibling;
                else
                        p->prev->nextSibling = p->nextSibling;
 
-               p->nextSibling = NULL;
+               p->nextSibling = nullptr;
                compareAndLink( root, p );
        }
 }
@@ -206,9 +206,9 @@ void PairingHeap<T>::decreaseKey( PairNode<T> *p,
 /**
 * Internal method that is the basic operation to maintain order.
 * Links first and second together to satisfy heap order.
-* first is root of tree 1, which may not be NULL.
-*    first->nextSibling MUST be NULL on entry.
-* second is root of tree 2, which may be NULL.
+* first is root of tree 1, which may not be nullptr.
+*    first->nextSibling MUST be nullptr on entry.
+* second is root of tree 2, which may be nullptr.
 * first becomes the result of the tree merge.
 */
 template <class T>
@@ -216,7 +216,7 @@ void PairingHeap<T>::
 compareAndLink( PairNode<T> * & first,
                           PairNode<T> *second ) const
 {
-       if( second == NULL )
+       if( second == nullptr )
                return;
        if( lessThan(second->element,first->element) )
        {
@@ -224,7 +224,7 @@ compareAndLink( PairNode<T> * & first,
                second->prev = first->prev;
                first->prev = second;
                first->nextSibling = second->leftChild;
-               if( first->nextSibling != NULL )
+               if( first->nextSibling != nullptr )
                        first->nextSibling->prev = first;
                second->leftChild = first;
                first = second;
@@ -234,10 +234,10 @@ compareAndLink( PairNode<T> * & first,
                // Attach second as leftmost child of first
                second->prev = first;
                first->nextSibling = second->nextSibling;
-               if( first->nextSibling != NULL )
+               if( first->nextSibling != nullptr )
                        first->nextSibling->prev = first;
                second->nextSibling = first->leftChild;
-               if( second->nextSibling != NULL )
+               if( second->nextSibling != nullptr )
                        second->nextSibling->prev = second;
                first->leftChild = second;
        }
@@ -246,13 +246,13 @@ compareAndLink( PairNode<T> * & first,
 /**
 * Internal method that implements two-pass merging.
 * firstSibling the root of the conglomerate;
-*     assumed not NULL.
+*     assumed not nullptr.
 */
 template <class T>
 PairNode<T> *
 PairingHeap<T>::combineSiblings( PairNode<T> *firstSibling ) const
 {
-       if( firstSibling->nextSibling == NULL )
+       if( firstSibling->nextSibling == nullptr )
                return firstSibling;
 
        // Allocate the array
@@ -260,17 +260,17 @@ PairingHeap<T>::combineSiblings( PairNode<T> *firstSibling ) const
 
        // Store the subtrees in an array
        int numSiblings = 0;
-       for( ; firstSibling != NULL; numSiblings++ )
+       for( ; firstSibling != nullptr; numSiblings++ )
        {
                if( numSiblings == (int)treeArray.size( ) )
                        treeArray.resize( numSiblings * 2 );
                treeArray[ numSiblings ] = firstSibling;
-               firstSibling->prev->nextSibling = NULL;  // break links
+               firstSibling->prev->nextSibling = nullptr;  // break links
                firstSibling = firstSibling->nextSibling;
        }
        if( numSiblings == (int)treeArray.size( ) )
                treeArray.resize( numSiblings + 1 );
-       treeArray[ numSiblings ] = NULL;
+       treeArray[ numSiblings ] = nullptr;
 
        // Combine subtrees two at a time, going left to right
        int i = 0;
@@ -299,14 +299,14 @@ template <class T>
 PairNode<T> *
 PairingHeap<T>::clone( PairNode<T> * t ) const
 {
-       if( t == NULL ) 
-               return NULL;
+       if( t == nullptr ) 
+               return nullptr;
        else
        {
                PairNode<T> *p = new PairNode<T>( t->element );
-               if( ( p->leftChild = clone( t->leftChild ) ) != NULL )
+               if( ( p->leftChild = clone( t->leftChild ) ) != nullptr )
                        p->leftChild->prev = p;
-               if( ( p->nextSibling = clone( t->nextSibling ) ) != NULL )
+               if( ( p->nextSibling = clone( t->nextSibling ) ) != nullptr )
                        p->nextSibling->prev = p;
                return p;
        }
@@ -315,17 +315,17 @@ template <class T>
 ostream& operator <<(ostream &os, const PairingHeap<T> &b)
 {
        os<<"Heap:";
-       if (b.root != NULL) {
+       if (b.root != nullptr) {
                PairNode<T> *r = b.root;
                list<PairNode<T>*> q;
                q.push_back(r);
                while (!q.empty()) {
                        r = q.front();
                        q.pop_front();
-                       if (r->leftChild != NULL) {
+                       if (r->leftChild != nullptr) {
                                os << *r->element << ">";
                                PairNode<T> *c = r->leftChild;
-                               while (c != NULL) {
+                               while (c != nullptr) {
                                        q.push_back(c);
                                        os << "," << *c->element;
                                        c = c->nextSibling;
index 555f13b5123cbabffa208eb2bf3c9193fb7357c5..5b3e7457b3e0f73bc0cd7a9ddbf3e2efa751827a 100644 (file)
@@ -61,7 +61,7 @@ class PairNode
 
        PairNode( const T & theElement ) :
                element( theElement ),
-               leftChild(NULL), nextSibling(NULL), prev(NULL)
+               leftChild(nullptr), nextSibling(nullptr), prev(nullptr)
                { }
        friend class PairingHeap<T>;
 };
@@ -94,8 +94,8 @@ public:
        void merge( PairingHeap<T> *rhs )
        {       
                PairNode<T> *broot=rhs->getRoot();
-               if (root == NULL) {
-                       if(broot != NULL) {
+               if (root == nullptr) {
+                       if(broot != nullptr) {
                                root = broot;
                        }
                } else {
@@ -108,7 +108,7 @@ public:
 protected:
        PairNode<T> * getRoot() {
                PairNode<T> *r=root;
-               root=NULL;
+               root=nullptr;
                return r;
        }
 private:
index bc10c9b5347eb04fd5ec5afc2d1c33c8bf3711ea..184150529bbb30c95dad0c87637b75659863a42a 100644 (file)
@@ -110,13 +110,13 @@ void VPSC::refine() {
                for(set<Block*>::const_iterator i=bs->begin();i!=bs->end();i++) {
                        Block *b=*i;
                        Constraint *c=b->findMinLM();
-                       if(c!=NULL && c->lm<0) {
+                       if(c!=nullptr && c->lm<0) {
                                if (RECTANGLE_OVERLAP_LOGGING) {
                                        ofstream f(LOGFILE,ios::app);
                                        f<<"Split on constraint: "<<*c<<"\n";
                                }
                                // Split on c
-                               Block *l=NULL, *r=NULL;
+                               Block *l=nullptr, *r=nullptr;
                                bs->split(b,l,r,c);
                                bs->cleanup();
                                // split alters the block set so we have to restart
@@ -180,7 +180,7 @@ void IncVPSC::satisfy() {
        }
        splitBlocks();
        long splitCtr = 0;
-       Constraint* v = NULL;
+       Constraint* v = nullptr;
        while(mostViolated(inactive,v)<-0.0000001) {
                assert(!v->active);
                Block *lb = v->left->block, *rb = v->right->block;
@@ -238,13 +238,13 @@ void IncVPSC::splitBlocks() {
        for(set<Block*>::const_iterator i(bs->begin());i!=bs->end();i++) {
                Block* b = *i;
                Constraint* v=b->findMinLM();
-               if(v!=NULL && v->lm < -0.0000001) {
+               if(v!=nullptr && v->lm < -0.0000001) {
                        if (RECTANGLE_OVERLAP_LOGGING) {
                                ofstream f(LOGFILE,ios::app);
                                f<<"    found split point: "<<*v<<" lm="<<v->lm<<"\n";
                        }
                        splitCnt++;
-                       Block *b = v->left->block, *l=NULL, *r=NULL;
+                       Block *b = v->left->block, *l=nullptr, *r=nullptr;
                        assert(v->left->block == v->right->block);
                        double pos = b->posn;
                        b->split(l,r,v);
@@ -333,7 +333,7 @@ bool VPSC::constraintGraphIsCyclic(const unsigned n, Variable *vs[]) {
                }
        }
        while(!graph.empty()) {
-               node *u=NULL;
+               node *u=nullptr;
                vector<node*>::iterator i=graph.begin();
                for(;i!=graph.end();i++) {
                        u=*i;
@@ -373,7 +373,7 @@ bool VPSC::blockGraphIsCyclic() {
                Block *b=*i;
                b->setUpInConstraints();
                Constraint *c=b->findMinInConstraint();
-               while(c!=NULL) {
+               while(c!=nullptr) {
                        Block *l=c->left->block;
                        bmap[b]->in.insert(bmap[l]);
                        b->deleteMinInConstraint();
@@ -382,7 +382,7 @@ bool VPSC::blockGraphIsCyclic() {
 
                b->setUpOutConstraints();
                c=b->findMinOutConstraint();
-               while(c!=NULL) {
+               while(c!=nullptr) {
                        Block *r=c->right->block;
                        bmap[b]->out.insert(bmap[r]);
                        b->deleteMinOutConstraint();
@@ -390,7 +390,7 @@ bool VPSC::blockGraphIsCyclic() {
                }
        }
        while(!graph.empty()) {
-               node *u=NULL;
+               node *u=nullptr;
                vector<node*>::iterator i=graph.begin();
                for(;i!=graph.end();i++) {
                        u=*i;