Performance : Use map to speed up search

This commit is contained in:
Magne Sjaastad 2020-05-04 19:35:01 +02:00
parent bb40453ae4
commit abd4b7c769
2 changed files with 9 additions and 8 deletions

View File

@ -314,6 +314,7 @@ size_t RigCaseCellResultsData::findOrCreateScalarResultIndex( const RigEclipseRe
RigEclipseResultInfo resInfo( resVarAddr, needsToBeStored, false, scalarResultIndex ); RigEclipseResultInfo resInfo( resVarAddr, needsToBeStored, false, scalarResultIndex );
m_resultInfos.push_back( resInfo ); m_resultInfos.push_back( resInfo );
m_addressToResultIndexMap[resVarAddr] = scalarResultIndex;
// Create statistics calculator and add statistics cache object // Create statistics calculator and add statistics cache object
// Todo: Move to a "factory" method // Todo: Move to a "factory" method
@ -730,6 +731,7 @@ void RigCaseCellResultsData::clearAllResults()
{ {
m_cellScalarResults.clear(); m_cellScalarResults.clear();
m_resultInfos.clear(); m_resultInfos.clear();
m_addressToResultIndexMap.clear();
m_statisticsDataCache.clear(); m_statisticsDataCache.clear();
} }
@ -3256,13 +3258,10 @@ size_t RigCaseCellResultsData::findScalarResultIndexFromAddress( const RigEclips
} }
else else
{ {
std::vector<RigEclipseResultInfo>::const_iterator it; auto index = m_addressToResultIndexMap.find( resVarAddr );
for ( it = m_resultInfos.begin(); it != m_resultInfos.end(); ++it ) if ( index != m_addressToResultIndexMap.end() )
{ {
if ( it->eclipseResultAddress() == resVarAddr ) return index->second;
{
return it->gridScalarResultIndex();
}
} }
return cvf::UNDEFINED_SIZE_T; return cvf::UNDEFINED_SIZE_T;

View File

@ -30,6 +30,7 @@
#include <QDateTime> #include <QDateTime>
#include <cmath> #include <cmath>
#include <map>
#include <vector> #include <vector>
class RifReaderInterface; class RifReaderInterface;
@ -201,6 +202,7 @@ private:
///< each Result index (ResultVariable) and timestep ///< each Result index (ResultVariable) and timestep
cvf::Collection<RigStatisticsDataCache> m_statisticsDataCache; cvf::Collection<RigStatisticsDataCache> m_statisticsDataCache;
std::vector<RigEclipseResultInfo> m_resultInfos; std::vector<RigEclipseResultInfo> m_resultInfos;
std::map<RigEclipseResultAddress, size_t> m_addressToResultIndexMap;
RigMainGrid* m_ownerMainGrid; RigMainGrid* m_ownerMainGrid;
RigEclipseCaseData* m_ownerCaseData; RigEclipseCaseData* m_ownerCaseData;