clang-format samples

This commit is contained in:
Lars Toenning
2023-04-09 17:00:46 +02:00
parent a3b5a9b780
commit 674710f146
24 changed files with 220 additions and 212 deletions

View File

@@ -62,10 +62,10 @@ int main(int argc, char *argv[])
const QString s = qtin.readLine().toLower().trimmed();
if (s.startsWith("1")) { CSamplesJson::samples(); }
else if (s.startsWith("2")) { CSamplesChangeObject::samples(); }
else if (s.startsWith("2")) { CSamplesChangeObject::samples(); }
else if (s.startsWith("3a")) { CSamplesContainer::samples(); }
else if (s.startsWith("3b")) { CSamplesPerformance::sampleQMapVsQHashByCallsign(qtout); }
else if (s.startsWith("4")) { CSamplesMetadata::samples(); }
else if (s.startsWith("4")) { CSamplesMetadata::samples(); }
else if (s.startsWith("6a")) { CSamplesPerformance::samplesMisc(qtout); }
else if (s.startsWith("6b")) { CSamplesPerformance::interpolatorScenario(qtout, 40, 20); }
else if (s.startsWith("6c")) { CSamplesPerformance::samplesJson(qtout); }
@@ -73,9 +73,9 @@ int main(int argc, char *argv[])
else if (s.startsWith("6e")) { CSamplesPerformance::samplesStringUtilsVsRegEx(qtout); }
else if (s.startsWith("6f")) { CSamplesPerformance::samplesStringConcat(qtout); }
else if (s.startsWith("6g")) { CSamplesPerformance::samplesStringLiteralVsConstQString(qtout); }
else if (s.startsWith("7")) { CSamplesAlgorithm::samples(); }
else if (s.startsWith("8")) { CSamplesFile::samples(qtout); }
else if (s.startsWith("x")) { break; }
else if (s.startsWith("7")) { CSamplesAlgorithm::samples(); }
else if (s.startsWith("8")) { CSamplesFile::samples(qtout); }
else if (s.startsWith("x")) { break; }
}
while (true);
return 0;

View File

@@ -45,7 +45,7 @@ namespace BlackSample
means.push_back(std::accumulate(randoms.cbegin(), randoms.cend(), 0) / 10);
}
int mean = std::accumulate(means.cbegin(), means.cend(), 0) / samples;
int stdDev = std::sqrt(std::accumulate(means.cbegin(), means.cend(), 0, [ & ](int a, int n) { return a + (n - mean) * (n - mean); }) / samples);
int stdDev = std::sqrt(std::accumulate(means.cbegin(), means.cend(), 0, [&](int a, int n) { return a + (n - mean) * (n - mean); }) / samples);
qDebug() << "randomElements";
qDebug() << "means:" << means;
qDebug() << "mean of the means:" << mean;
@@ -59,7 +59,7 @@ namespace BlackSample
means.push_back(std::accumulate(randoms.cbegin(), randoms.cend(), 0) / 10);
}
int mean = std::accumulate(means.cbegin(), means.cend(), 0) / samples;
int stdDev = std::sqrt(std::accumulate(means.cbegin(), means.cend(), 0, [ & ](int a, int n) { return a + (n - mean) * (n - mean); }) / samples);
int stdDev = std::sqrt(std::accumulate(means.cbegin(), means.cend(), 0, [&](int a, int n) { return a + (n - mean) * (n - mean); }) / samples);
qDebug() << "sampleElements";
qDebug() << "means:" << means;
qDebug() << "mean of the means:" << mean;
@@ -72,7 +72,7 @@ namespace BlackSample
qDebug() << "topologicallySortedInsert";
QStringList dst;
int count = 0;
auto cmp = [ & ](const QString &a, const QString &b) { count++; return a[0] == b[0] && a[1] < b[1]; };
auto cmp = [&](const QString &a, const QString &b) { count++; return a[0] == b[0] && a[1] < b[1]; };
for (const auto &s : src) { BlackMisc::topologicallySortedInsert(dst, s, cmp); }
qDebug() << count << "comparisons";
qDebug() << dst;

View File

@@ -46,8 +46,8 @@ namespace BlackSample
geoPos, CLength(50, CLengthUnit::km()), false, dtFrom, dtUntil);
const CAtcStation station2(station1);
const CAtcStation station3(CCallsign("eddm_app"), CUser("654321", "Jen Doe"),
CFrequency(120.7, CFrequencyUnit::MHz()),
geoPos, CLength(100, CLengthUnit::km()), false, dtFrom2, dtUntil2);
CFrequency(120.7, CFrequencyUnit::MHz()),
geoPos, CLength(100, CLengthUnit::km()), false, dtFrom2, dtUntil2);
Q_ASSERT_X(station1 == station2, Q_FUNC_INFO, "Unequal stations");
@@ -74,7 +74,7 @@ namespace BlackSample
// now Jane's time is over
CPropertyIndexVariantMap anotherController;
anotherController.addValue(CAtcStation::IndexController, CVariant::fromValue(CUser("445566", "Fuzzy")));
atcList.applyIf([ = ](const auto &arg) { return newController.matches(arg); }, anotherController);
atcList.applyIf([=](const auto &arg) { return newController.matches(arg); }, anotherController);
qDebug() << "-- after update via value map";
qDebug() << atcList.toQString();

View File

@@ -54,7 +54,7 @@ namespace BlackSample
QTextStream cin(stdin);
CLength l(123.456, CLengthUnit::NM());
QJsonObject json = l.toJson();
l = CLength(); //convert back
l = CLength(); // convert back
l.convertFromJson(json);
qDebug() << json << l;
qDebug() << "-------";

View File

@@ -105,7 +105,7 @@ namespace BlackSample
timer.start();
CSamplesPerformance::accessStationsData(atcs2, false);
ms = timer.elapsed();
out << "Read (getters) " << atcs2.size() << " ATC stations in " << ms << "ms" << Qt::endl;
out << "Read (getters) " << atcs2.size() << " ATC stations in " << ms << "ms" << Qt::endl;
timer.start();
CSamplesPerformance::accessStationsData(atcs1, true);
@@ -163,26 +163,38 @@ namespace BlackSample
QString containsStr("aaa");
number = 0;
timer.start();
for (const auto &str : std::as_const(strList1)) { if (newRegex.match(str).hasMatch()) number++; }
for (const auto &str : std::as_const(strList1))
{
if (newRegex.match(str).hasMatch()) number++;
}
ms = timer.elapsed();
out << "new regex matched " << number << " of" << strList1.size() << " strings in " << ms << "ms" << Qt::endl;
out << "new regex matched " << number << " of" << strList1.size() << " strings in " << ms << "ms" << Qt::endl;
number = 0;
timer.start();
for (const auto &str : std::as_const(strList2)) { if (fullRegex.exactMatch(str)) number++; }
for (const auto &str : std::as_const(strList2))
{
if (fullRegex.exactMatch(str)) number++;
}
ms = timer.elapsed();
out << "full regex matched " << number << " of" << strList2.size() << " strings in " << ms << "ms" << Qt::endl;
out << "full regex matched " << number << " of" << strList2.size() << " strings in " << ms << "ms" << Qt::endl;
number = 0;
timer.start();
for (const auto &str : std::as_const(strList3)) { if (wildcardRegex.exactMatch(str)) number++; }
for (const auto &str : std::as_const(strList3))
{
if (wildcardRegex.exactMatch(str)) number++;
}
ms = timer.elapsed();
out << "wildcard matched " << number << " of " << strList3.size() << " strings in " << ms << "ms" << Qt::endl;
out << "wildcard matched " << number << " of " << strList3.size() << " strings in " << ms << "ms" << Qt::endl;
number = 0;
timer.start();
for (const auto &str : std::as_const(strList4)) { if (str.contains(containsStr)) number++; }
for (const auto &str : std::as_const(strList4))
{
if (str.contains(containsStr)) number++;
}
ms = timer.elapsed();
out << "contains matched " << number << " of " << strList4.size() << " strings in " << ms << "ms" << Qt::endl;
out << "-----------------------------------------------" << Qt::endl;
out << "-----------------------------------------------" << Qt::endl;
return EXIT_SUCCESS;
}
@@ -256,7 +268,8 @@ namespace BlackSample
timer.start();
situations.convertFromJson(json);
out << "Convert 100,000 aircraft situations from JSON: " << timer.elapsed() << "ms" << endl << Qt::endl;
out << "Convert 100,000 aircraft situations from JSON: " << timer.elapsed() << "ms" << endl
<< Qt::endl;
timer.start();
json = models.toJson();
@@ -264,7 +277,8 @@ namespace BlackSample
timer.start();
models.convertFromJson(json);
out << "Convert 10,000 aircraft models from JSON (naive): " << timer.elapsed() << "ms" << endl << Qt::endl;
out << "Convert 10,000 aircraft models from JSON (naive): " << timer.elapsed() << "ms" << endl
<< Qt::endl;
timer.start();
json = models.toMemoizedJson();
@@ -272,7 +286,8 @@ namespace BlackSample
timer.start();
models.convertFromMemoizedJson(json);
out << "Convert 10,000 aircraft models from JSON (memoize): " << timer.elapsed() << "ms" << endl << Qt::endl;
out << "Convert 10,000 aircraft models from JSON (memoize): " << timer.elapsed() << "ms" << endl
<< Qt::endl;
return EXIT_SUCCESS;
}
@@ -349,8 +364,7 @@ namespace BlackSample
QElapsedTimer timer;
static const QString chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~_-=+!\"@#$%^&*()[]{} \t;:\\/?,.<>";
QStringList strings;
std::generate_n(std::back_inserter(strings), 100000, []
{
std::generate_n(std::back_inserter(strings), 100000, [] {
QString s;
std::generate_n(std::back_inserter(s), 10, [] { return chars[CMathUtils::randomInteger(0, chars.size() - 1)]; });
return s;
@@ -374,7 +388,8 @@ namespace BlackSample
auto c = s.contains(upperRegex);
Q_UNUSED(c);
}
out << "Check 100,000 strings for containing uppercase letter: (regex) " << timer.elapsed() << "ms" << endl << Qt::endl;
out << "Check 100,000 strings for containing uppercase letter: (regex) " << timer.elapsed() << "ms" << endl
<< Qt::endl;
timer.start();
for (const QString &s : std::as_const(strings))
@@ -390,7 +405,8 @@ namespace BlackSample
auto i = s.indexOf(upperRegex);
Q_UNUSED(i);
}
out << "Check 100,000 strings for index of first uppercase letter: (regex) " << timer.elapsed() << "ms" << endl << Qt::endl;
out << "Check 100,000 strings for index of first uppercase letter: (regex) " << timer.elapsed() << "ms" << endl
<< Qt::endl;
auto temp = strings;
timer.start();
@@ -406,7 +422,8 @@ namespace BlackSample
{
s.remove(upperRegex);
}
out << "Remove from 100,000 strings all uppercase letters: (regex) " << timer.elapsed() << "ms" << endl << Qt::endl;
out << "Remove from 100,000 strings all uppercase letters: (regex) " << timer.elapsed() << "ms" << endl
<< Qt::endl;
timer.start();
{
@@ -714,16 +731,13 @@ namespace BlackSample
if (n < 1) { return; }
CAtcStation atc = CTesting::createStation(1);
const QList<CCoordinateGeodetic> pos(
{
CCoordinateGeodetic(10.0, 10.0, 10.0),
CCoordinateGeodetic(20.0, 20.0, 20.0),
CCoordinateGeodetic(30.0, 30.0, 30.0),
CCoordinateGeodetic(40.0, 40.0, 40.0),
CCoordinateGeodetic(50.0, 50.0, 50.0),
CCoordinateGeodetic(60.0, 60.0, 60.0),
CCoordinateGeodetic(70.0, 70.0, 70.0)
}
);
{ CCoordinateGeodetic(10.0, 10.0, 10.0),
CCoordinateGeodetic(20.0, 20.0, 20.0),
CCoordinateGeodetic(30.0, 30.0, 30.0),
CCoordinateGeodetic(40.0, 40.0, 40.0),
CCoordinateGeodetic(50.0, 50.0, 50.0),
CCoordinateGeodetic(60.0, 60.0, 60.0),
CCoordinateGeodetic(70.0, 70.0, 70.0) });
const int s = pos.size();
for (int i = 0; i < n; i++)
{
@@ -745,13 +759,11 @@ namespace BlackSample
void CSamplesPerformance::parseWgs(int times)
{
static QStringList wgsLatLng(
{
"12° 11 10″ N", "11° 22 33W",
"48° 21 13″ N", "11° 47 09″ E",
" 8° 21 13″ N", "11° 47 09″ W",
"18° 21 13″ S", "11° 47 09″ E",
"09° 12 13″ S", "11° 47 09″ W"
});
{ "12° 11 10″ N", "11° 22 33″ W",
"48° 21 13″ N", "11° 47 09E",
" 8° 21 13″ N", "11° 47 09″ W",
"18° 21 13″ S", "11° 47 09″ E",
"09° 12 13″ S", "11° 47 09″ W" });
CCoordinateGeodetic c;
const CAltitude a(333, CLengthUnit::m());
@@ -775,12 +787,12 @@ namespace BlackSample
QStringList CSamplesPerformance::generateList()
{
return QStringList({"1", "2", "3", "4"});
return QStringList({ "1", "2", "3", "4" });
}
QStringList CSamplesPerformance::replacedList()
{
static const QStringList l({"1", "2", "3", "4"});
static const QStringList l({ "1", "2", "3", "4" });
QStringList lc(l);
lc[1] = QStringLiteral("6");
lc[3] = QStringLiteral("7");
@@ -840,13 +852,13 @@ namespace BlackSample
QString r;
if (byPropertyIndex)
{
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexCallsign, CCallsign::IndexString}).toString());
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexController, CUser::IndexRealName}).toString());
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexPosition, CCoordinateGeodetic::IndexLatitudeAsString}).toString());
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexPosition, CCoordinateGeodetic::IndexLongitudeAsString}).toString());
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexRelativeDistance, CLength::IndexValueRounded2DigitsWithUnit}).toString());
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexBookedFrom}).toDateTime().toString("yyyy-MM-dd hh:mm"));
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexBookedUntil}).toDateTime().toString("yyyy-MM-dd hh:mm"));
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexCallsign, CCallsign::IndexString }).toString());
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexController, CUser::IndexRealName }).toString());
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexPosition, CCoordinateGeodetic::IndexLatitudeAsString }).toString());
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexPosition, CCoordinateGeodetic::IndexLongitudeAsString }).toString());
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexRelativeDistance, CLength::IndexValueRounded2DigitsWithUnit }).toString());
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexBookedFrom }).toDateTime().toString("yyyy-MM-dd hh:mm"));
r.append(station.propertyByIndex(CPropertyIndex { CAtcStation::IndexBookedUntil }).toDateTime().toString("yyyy-MM-dd hh:mm"));
}
else
{