Skip to content
Permalink
Browse files

Slightly more efficiency in QgsStatisticalSummary

  • Loading branch information
nyalldawson committed Jan 22, 2019
1 parent d70191d commit 60a6fc13a531218e1ad2e7ed4b3cad09936b3745
Showing with 10 additions and 4 deletions.
  1. +8 −4 src/core/qgsstatisticalsummary.cpp
  2. +2 −0 src/core/qgsstatisticalsummary.h
@@ -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;
}

/***************************************************************************
@@ -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;
}

@@ -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 )

0 comments on commit 60a6fc1

Please sign in to comment.
You can’t perform that action at this time.