mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 12:35:43 +08:00
Issue #77 Break dependency of sequence on propertyindex
This commit is contained in:
@@ -12,7 +12,6 @@
|
|||||||
#define BLACKMISC_SEQUENCE_H
|
#define BLACKMISC_SEQUENCE_H
|
||||||
|
|
||||||
#include "blackmisc/containerbase.h"
|
#include "blackmisc/containerbase.h"
|
||||||
#include "blackmisc/propertyindex.h"
|
|
||||||
#include "blackmisc/mixin/mixinicon.h"
|
#include "blackmisc/mixin/mixinicon.h"
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -435,21 +434,6 @@ namespace BlackMisc
|
|||||||
sort(BlackMisc::Predicates::MemberLess(key1, keys...));
|
sort(BlackMisc::Predicates::MemberLess(key1, keys...));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! In-place sort by some properties specified by a list of property indexes.
|
|
||||||
void sortByProperty(const CSequence<CPropertyIndex> &indexes)
|
|
||||||
{
|
|
||||||
sort([&indexes](const T &a, const T &b)
|
|
||||||
{
|
|
||||||
for (const auto &index : indexes)
|
|
||||||
{
|
|
||||||
int cmp = index.comparator()(a, b);
|
|
||||||
if (cmp < 0) { return true; }
|
|
||||||
if (cmp > 0) { return false; }
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Return a copy sorted by a given comparator predicate.
|
//! Return a copy sorted by a given comparator predicate.
|
||||||
template <class Predicate>
|
template <class Predicate>
|
||||||
CSequence sorted(Predicate p) const
|
CSequence sorted(Predicate p) const
|
||||||
@@ -468,14 +452,6 @@ namespace BlackMisc
|
|||||||
return sorted(BlackMisc::Predicates::MemberLess(key1, keys...));
|
return sorted(BlackMisc::Predicates::MemberLess(key1, keys...));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Return a copy sorted by some properties specified by a list of property indexes.
|
|
||||||
CSequence sortedByProperty(const CSequence<CPropertyIndex> &indexes) const
|
|
||||||
{
|
|
||||||
CSequence result = *this;
|
|
||||||
result.sortByProperty(indexes);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! In-place move the smallest n elements to the beginning and sort them.
|
//! In-place move the smallest n elements to the beginning and sort them.
|
||||||
template <class Predicate> void partiallySort(size_type n, Predicate p)
|
template <class Predicate> void partiallySort(size_type n, Predicate p)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -74,8 +74,6 @@ namespace BlackMiscTest
|
|||||||
QVERIFY(v3 == v33 && v3 == 0);
|
QVERIFY(v3 == v33 && v3 == 0);
|
||||||
|
|
||||||
QVERIFY(callsigns.front().equalsString("DLH3000"));
|
QVERIFY(callsigns.front().equalsString("DLH3000"));
|
||||||
callsigns.sortByProperty(indexListCs);
|
|
||||||
QVERIFY(callsigns.front().equalsString("DLH1000"));
|
|
||||||
|
|
||||||
CStatusMessage s1(CStatusMessage::SeverityDebug, u"debug msg.");
|
CStatusMessage s1(CStatusMessage::SeverityDebug, u"debug msg.");
|
||||||
s1.setMSecsSinceEpoch(4000);
|
s1.setMSecsSinceEpoch(4000);
|
||||||
@@ -110,9 +108,6 @@ namespace BlackMiscTest
|
|||||||
|
|
||||||
QVERIFY(msgs.front().getMSecsSinceEpoch() == 4000);
|
QVERIFY(msgs.front().getMSecsSinceEpoch() == 4000);
|
||||||
QVERIFY(msgs.back().getMSecsSinceEpoch() == 1000);
|
QVERIFY(msgs.back().getMSecsSinceEpoch() == 1000);
|
||||||
msgs.sortByProperty(indexList);
|
|
||||||
QVERIFY(msgs.front().getMSecsSinceEpoch() == 1000);
|
|
||||||
QVERIFY(msgs.back().getMSecsSinceEpoch() == 4000);
|
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user