mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
refs #570 Removed unused method splitByTime.
This commit is contained in:
@@ -303,34 +303,6 @@ namespace BlackSample
|
||||
Q_UNUSED(a);
|
||||
Q_UNUSED(b);
|
||||
|
||||
timer.start();
|
||||
QList<CAircraftSituationList> split = situations.splitByTime(halfTime);
|
||||
for (int cs = 0; cs < numberOfCallsigns; cs++)
|
||||
{
|
||||
CCallsign callsign("CS" + QString::number(cs));
|
||||
CAircraftSituationList csSituationsBefore = split[0].findByCallsign(callsign);
|
||||
CAircraftSituationList csSituationsAfter = split[1].findByCallsign(callsign);
|
||||
Q_UNUSED(csSituationsBefore);
|
||||
Q_UNUSED(csSituationsAfter);
|
||||
}
|
||||
out << "Single split by time upfront, then callsigns: " << timer.elapsed() << "ms" << endl;
|
||||
b = split[0].size();
|
||||
a = split[1].size();
|
||||
Q_ASSERT(a + b == numberOfTimes * numberOfCallsigns);
|
||||
|
||||
situations.sortLatestFirst(); // eliminate impact of sort
|
||||
timer.start();
|
||||
split = situations.splitByTime(halfTime);
|
||||
for (int cs = 0; cs < numberOfCallsigns; cs++)
|
||||
{
|
||||
CCallsign callsign("CS" + QString::number(cs));
|
||||
CAircraftSituationList csSituationsBefore = split[0].findByCallsign(callsign);
|
||||
CAircraftSituationList csSituationsAfter = split[1].findByCallsign(callsign);
|
||||
Q_UNUSED(csSituationsBefore);
|
||||
Q_UNUSED(csSituationsAfter);
|
||||
}
|
||||
out << "Single, pre-sorted split by time upfront, then callsigns: " << timer.elapsed() << "ms" << endl;
|
||||
|
||||
timer.start();
|
||||
QHash<CCallsign, CAircraftSituationList> csSituations = situations.splitPerCallsign();
|
||||
out << "Split by " << csSituations.size() << " callsigns, " << timer.elapsed() << "ms" << endl;
|
||||
|
||||
@@ -102,32 +102,6 @@ namespace BlackMisc
|
||||
return this->container().contains(&OBJ::hasValidTimestamp, false);
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
QList<CONTAINER> ITimestampObjectList<OBJ, CONTAINER>::splitByTime(qint64 msSinceEpoch, bool sortedLatestFirst) const
|
||||
{
|
||||
QList<CONTAINER> result { {}, {} };
|
||||
const auto &c = this->container();
|
||||
if (sortedLatestFirst)
|
||||
{
|
||||
// O(log n) comparisons and O(n) copies
|
||||
struct Comparator
|
||||
{
|
||||
bool operator()(const OBJ &a, qint64 b) const { return a.isNewerThan(b); }
|
||||
bool operator()(qint64 a, const OBJ &b) const { return b.isOlderThan(a); }
|
||||
};
|
||||
auto it = std::upper_bound(c.begin(), c.end(), msSinceEpoch, Comparator());
|
||||
std::copy(c.begin(), it, std::back_inserter(result[0]));
|
||||
std::copy(it, c.end(), std::back_inserter(result[1]));
|
||||
}
|
||||
else
|
||||
{
|
||||
// O(n) comparisons and O(n) copies
|
||||
std::partition_copy(c.begin(), c.end(), std::back_inserter(result[0]), std::back_inserter(result[1]),
|
||||
[msSinceEpoch](const OBJ & obj) { return ! obj.isNewerThan(msSinceEpoch); });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER>
|
||||
QDateTime ITimestampObjectList<OBJ, CONTAINER>::latestTimestamp() const
|
||||
{
|
||||
|
||||
@@ -50,10 +50,6 @@ namespace BlackMisc
|
||||
//! Has invalid timestamp
|
||||
bool hasInvalidTimestamps() const;
|
||||
|
||||
//! Partition into two containers, first [0,msSinceEpoch] and second (msSinceEpoch,LLONG_MAX].
|
||||
//! Within each of the two parts, the original relative ordering of the elements is preserved.
|
||||
QList<CONTAINER> splitByTime(qint64 msSinceEpoch, bool sortedLatestFirst = false) const;
|
||||
|
||||
//! Latest timestamp
|
||||
QDateTime latestTimestamp() const;
|
||||
|
||||
|
||||
@@ -254,26 +254,6 @@ namespace BlackMiscTest
|
||||
ms = situations.front().getMSecsSinceEpoch();
|
||||
QVERIFY2(ms == ts, "Latest value not first");
|
||||
|
||||
// split in half
|
||||
for (bool sortLatestFirst : { false, true })
|
||||
{
|
||||
sortLatestFirst ? situations.sortLatestFirst() : situations.sortOldestFirst();
|
||||
qint64 splitTime = ts - ((no / 2) * 10) + 1;
|
||||
QList<CAircraftSituationList> split = situations.splitByTime(splitTime);
|
||||
CAircraftSituationList before = split[0];
|
||||
CAircraftSituationList after = split[1];
|
||||
|
||||
int beforeSize = before.size();
|
||||
int afterSize = after.size();
|
||||
QVERIFY(beforeSize == no / 2);
|
||||
QVERIFY(afterSize == no / 2);
|
||||
|
||||
// check partitioning
|
||||
auto isNewer = [splitTime](const CAircraftSituation &as) { return as.isNewerThan(splitTime); };
|
||||
QVERIFY2(std::none_of(before.cbegin(), before.cend(), isNewer), "before contains a time which is after");
|
||||
QVERIFY2(std::all_of(after.cbegin(), after.cend(), isNewer), "after contains a time which is before");
|
||||
}
|
||||
|
||||
// test shifting
|
||||
situations.clear();
|
||||
const int maxElements = 8;
|
||||
|
||||
Reference in New Issue
Block a user