Skip to content
Permalink
Browse files

Slightly more efficiency in QgsStatisticalSummary

(cherry picked from commit 60a6fc1)
  • Loading branch information
nyalldawson committed Jan 24, 2019
1 parent a3428e5 commit b2a2251fea6571ecb8d2647d71c7ff53d25392ec
Showing with 10 additions and 4 deletions.
  1. +8 −4 src/core/qgsstatisticalsummary.cpp
  2. +2 −0 src/core/qgsstatisticalsummary.h
@@ -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;
}

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

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

0 comments on commit b2a2251

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