Skip to content

Commit

Permalink
More raw double arrays to vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 3, 2019
1 parent fe9dcf1 commit 499f240
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/core/pal/labelposition.cpp
Expand Up @@ -476,7 +476,7 @@ bool LabelPosition::countFullOverlapCallback( LabelPosition *lp, void *ctx )
LabelPosition *lp2 = context->lp;
double *cost = context->cost;
int *nbOv = context->nbOv;
double *inactiveCost = context->inactiveCost;
std::vector< double > &inactiveCost = *context->inactiveCost;
if ( lp2->isInConflict( lp ) )
{
( *nbOv ) ++;
Expand Down
3 changes: 1 addition & 2 deletions src/core/pal/labelposition.h
Expand Up @@ -281,8 +281,7 @@ namespace pal
LabelPosition *lp = nullptr;
int *nbOv = nullptr;
double *cost = nullptr;
double *inactiveCost = nullptr;
//int *feat;
std::vector< double > *inactiveCost = nullptr;
};

/*
Expand Down
6 changes: 3 additions & 3 deletions src/core/pal/pal.cpp
Expand Up @@ -325,9 +325,9 @@ std::unique_ptr<Problem> Pal::extract( const QgsRectangle &extent, const QgsGeom

prob->mFeatureCount = features.size();
prob->mTotalCandidates = 0;
prob->mFeatNbLp = new int [prob->mFeatureCount];
prob->mFeatStartId = new int [prob->mFeatureCount];
prob->mInactiveCost = new double[prob->mFeatureCount];
prob->mFeatNbLp.resize( prob->mFeatureCount );
prob->mFeatStartId.resize( prob->mFeatureCount );
prob->mInactiveCost.resize( prob->mFeatureCount );

if ( !features.empty() )
{
Expand Down
16 changes: 5 additions & 11 deletions src/core/pal/problem.cpp
Expand Up @@ -57,13 +57,7 @@ inline void delete_chain( Chain *chain )

Problem::Problem() = default;

Problem::~Problem()
{
delete[] mFeatStartId;
delete[] mFeatNbLp;

delete[] mInactiveCost;
}
Problem::~Problem() = default;

void Problem::reduce()
{
Expand Down Expand Up @@ -302,7 +296,7 @@ struct ChainContext
QLinkedList<ElemTrans *> *currentChain;
QLinkedList<int> *conflicts;
double *delta_tmp = nullptr;
double *inactiveCost = nullptr;
std::vector< double > *inactiveCost = nullptr;

} ;

Expand Down Expand Up @@ -346,7 +340,7 @@ bool chainCallback( LabelPosition *lp, void *context )
if ( !ctx->conflicts->contains( feat ) )
{
ctx->conflicts->append( feat );
*ctx->delta_tmp += lp->cost() + ctx->inactiveCost[rfeat];
*ctx->delta_tmp += lp->cost() + ( * ctx->inactiveCost )[rfeat];
}
}
return true;
Expand Down Expand Up @@ -386,7 +380,7 @@ inline Chain *Problem::chain( int seed )
context.featWrap = nullptr;
context.borderSize = 0;
context.tmpsol = &tmpsol;
context.inactiveCost = mInactiveCost;
context.inactiveCost = &mInactiveCost;
context.feat = nullptr;
context.currentChain = &currentChain;
context.conflicts = &conflicts;
Expand Down Expand Up @@ -786,7 +780,7 @@ void Problem::solution_cost()
int nbOv;

LabelPosition::CountContext context;
context.inactiveCost = mInactiveCost;
context.inactiveCost = &mInactiveCost;
context.nbOv = &nbOv;
context.cost = &mSol.totalCost;
double amin[2];
Expand Down
7 changes: 3 additions & 4 deletions src/core/pal/problem.h
Expand Up @@ -183,10 +183,9 @@ namespace pal

std::vector< std::unique_ptr< LabelPosition > > mPositionsWithNoCandidates;

//int *feat; // [nblp]
int *mFeatStartId = nullptr; // [nbft]
int *mFeatNbLp = nullptr; // [nbft]
double *mInactiveCost = nullptr; //
std::vector< int > mFeatStartId;
std::vector< int > mFeatNbLp;
std::vector< double > mInactiveCost;

class Sol
{
Expand Down

0 comments on commit 499f240

Please sign in to comment.