diff --git a/samples/blackmisc/samplesperformance.cpp b/samples/blackmisc/samplesperformance.cpp index 86fb443f8..7bdeb32ab 100644 --- a/samples/blackmisc/samplesperformance.cpp +++ b/samples/blackmisc/samplesperformance.cpp @@ -186,6 +186,18 @@ namespace BlackMiscTest } out << "Reads by callsigns: " << timer.elapsed() << "ms" << endl; + timer.start(); + for (int i = 0; i < 10; i++) + { + QMap splitList = situations.splitPerCallsign(); + Q_ASSERT(splitList.size() == numberOfCallsigns); + for (const CAircraftSituationList &slcs : splitList.values()) + { + Q_ASSERT(slcs.size() == numberOfTimes); + } + } + out << "Reads by callsigns split: " << timer.elapsed() << "ms" << endl; + timer.start(); for (int i = 0; i < 10; i++) { @@ -204,9 +216,10 @@ namespace BlackMiscTest { CCallsign callsign("CS" + QString::number(cs)); CAircraftSituationList r = situations.findByCallsign(callsign).findBefore(baseTimeEpoch + 1 + (10 * t)); + Q_UNUSED(r); } } - out << "Reads by callsign / times: " << timer.elapsed() << "ms" << endl; + out << "Reads by callsigns / times: " << timer.elapsed() << "ms" << endl; timer.start(); for (int t = 0; t < numberOfTimes; t++) @@ -215,9 +228,23 @@ namespace BlackMiscTest { CCallsign callsign("CS" + QString::number(cs)); CAircraftSituationList r = situations.findBefore(baseTimeEpoch + 1 + (10 * t)).findByCallsign(callsign); + Q_UNUSED(r); } } - out << "Reads by times / callsign: " << timer.elapsed() << "ms" << endl; + out << "Reads by times / callsigns: " << timer.elapsed() << "ms" << endl; + + timer.start(); + for (int t = 0; t < numberOfTimes; t++) + { + QMap splitList = situations.splitPerCallsign(); + Q_ASSERT(splitList.size() == numberOfCallsigns); + for (const CAircraftSituationList &slcs : splitList.values()) + { + CAircraftSituationList r = slcs.findBefore(baseTimeEpoch + 1 + (10 * t)); + Q_UNUSED(r); + } + } + out << "Split reads by callsigns / times: " << timer.elapsed() << "ms" << endl; situations.changeImpl >(); out << "Changed to QVector" << endl; diff --git a/src/blackmisc/avcallsignobjectlist.cpp b/src/blackmisc/avcallsignobjectlist.cpp index b5f27d1cd..169e1477d 100644 --- a/src/blackmisc/avcallsignobjectlist.cpp +++ b/src/blackmisc/avcallsignobjectlist.cpp @@ -99,6 +99,40 @@ namespace BlackMisc return r; } + template + QMap ICallsignObjectList::splitPerCallsign() const + { + CONTAINER copyContainer(getContainer()); + copyContainer.sortByCallsign(); + QMap result; + CCallsign cs; + for (const OBJ &csObj : copyContainer) + { + if (csObj.getCallsign().isEmpty()) + { + Q_ASSERT(false); // there should be no empty callsigns + continue; + } + if (cs != csObj.getCallsign()) + { + cs = csObj.getCallsign(); + CONTAINER perCallsign({ csObj }); + result.insert(cs, perCallsign); + } + else + { + result[cs].push_back(csObj); + } + } + return result; + } + + template + void ICallsignObjectList::sortByCallsign() + { + getContainer().sortBy(&OBJ::getCallsign); + } + template int ICallsignObjectList::incrementalUpdateOrAdd(const OBJ &objectBeforeChanges, const CPropertyIndexVariantMap &changedValues) { diff --git a/src/blackmisc/avcallsignobjectlist.h b/src/blackmisc/avcallsignobjectlist.h index ba68fdefa..92af08291 100644 --- a/src/blackmisc/avcallsignobjectlist.h +++ b/src/blackmisc/avcallsignobjectlist.h @@ -57,6 +57,12 @@ namespace BlackMisc //! All suffixes with their respective count QMap getSuffixes() const; + //! Split into 0..n containers as per callsign + QMap splitPerCallsign() const; + + //! Sort by callsign + void sortByCallsign(); + //! Incremental update or add object int incrementalUpdateOrAdd(const OBJ &objectBeforeChanged, const BlackMisc::CPropertyIndexVariantMap &changedValues);