Skip to content

Commit

Permalink
Slightly more efficiency in QgsStatisticalSummary
Browse files Browse the repository at this point in the history
(cherry picked from commit 60a6fc1)
  • Loading branch information
nyalldawson committed Jan 24, 2019
1 parent a3428e5 commit b2a2251
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/core/qgsstatisticalsummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ void QgsStatisticalSummary::reset()
mThirdQuartile = 0;
mValueCount.clear();
mValues.clear();

mRequiresHisto = mStatistics & QgsStatisticalSummary::Majority || mStatistics & QgsStatisticalSummary::Minority || mStatistics & QgsStatisticalSummary::Variety;

mRequiresAllValueStorage = mStatistics & QgsStatisticalSummary::StDev || mStatistics & QgsStatisticalSummary::StDevSample ||
mStatistics & QgsStatisticalSummary::Median || mStatistics & QgsStatisticalSummary::FirstQuartile ||
mStatistics & QgsStatisticalSummary::ThirdQuartile || mStatistics & QgsStatisticalSummary::InterQuartileRange;
}

/***************************************************************************
Expand Down Expand Up @@ -74,12 +80,10 @@ void QgsStatisticalSummary::addValue( double value )
mMin = std::min( mMin, value );
mMax = std::max( mMax, value );

if ( mStatistics & QgsStatisticalSummary::Majority || mStatistics & QgsStatisticalSummary::Minority || mStatistics & QgsStatisticalSummary::Variety )
if ( mRequiresHisto )
mValueCount.insert( value, mValueCount.value( value, 0 ) + 1 );

if ( mStatistics & QgsStatisticalSummary::StDev || mStatistics & QgsStatisticalSummary::StDevSample ||
mStatistics & QgsStatisticalSummary::Median || mStatistics & QgsStatisticalSummary::FirstQuartile ||
mStatistics & QgsStatisticalSummary::ThirdQuartile || mStatistics & QgsStatisticalSummary::InterQuartileRange )
if ( mRequiresAllValueStorage )
mValues << value;
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsstatisticalsummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ class CORE_EXPORT QgsStatisticalSummary
double mThirdQuartile;
QMap< double, int > mValueCount;
QList< double > mValues;
bool mRequiresAllValueStorage = false;
bool mRequiresHisto = false;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsStatisticalSummary::Statistics )
Expand Down

0 comments on commit b2a2251

Please sign in to comment.