Skip to content

Commit

Permalink
Slightly more efficiency in QgsStatisticalSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 22, 2019
1 parent d70191d commit 60a6fc1
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 @@ -49,6 +49,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 @@ -79,12 +85,10 @@ void QgsStatisticalSummary::addValue( double value )
mMax = std::max( mMax, value );
mLast = 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 @@ -319,6 +319,8 @@ class CORE_EXPORT QgsStatisticalSummary
double mLast;
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 60a6fc1

Please sign in to comment.