18 #include <QStringList>
27 namespace swift::sample
32 for (
int i = 1; i <= 100; ++i) { seq.
push_back(i); }
36 for (
int i = 0; i <
samples; ++i)
39 means.
push_back(std::accumulate(randoms.cbegin(), randoms.cend(), 0) / 10);
42 int stdDev = std::sqrt(std::accumulate(means.
cbegin(), means.
cend(), 0,
43 [&](
int a,
int n) { return a + (n - mean) * (n - mean); }) /
45 qDebug() <<
"randomElements";
46 qDebug() <<
"means:" << means;
47 qDebug() <<
"mean of the means:" << mean;
48 qDebug() <<
"std deviation of the means:" << stdDev;
52 for (
int i = 0; i <
samples; ++i)
55 means.
push_back(std::accumulate(randoms.cbegin(), randoms.cend(), 0) / 10);
58 int stdDev = std::sqrt(std::accumulate(means.
cbegin(), means.
cend(), 0,
59 [&](
int a,
int n) { return a + (n - mean) * (n - mean); }) /
61 qDebug() <<
"sampleElements";
62 qDebug() <<
"means:" << means;
63 qDebug() <<
"mean of the means:" << mean;
64 qDebug() <<
"std deviation of the means:" << stdDev;
67 QStringList src {
"a1",
"a2",
"a3",
"b1",
"b2",
"b3",
"c1",
"c2",
"c3" };
68 std::shuffle(src.begin(), src.end(), std::mt19937(
static_cast<unsigned>(std::time(
nullptr))));
70 qDebug() <<
"topologicallySortedInsert";
73 auto cmp = [&](
const QString &a,
const QString &b) {
75 return a[0] == b[0] && a[1] < b[1];
78 qDebug() << count <<
"comparisons";
80 qDebug() <<
"topologicalSort";
83 qDebug() << count <<
"comparisons";
Derived sampleElements(int n) const
Copy n elements from the container, randomly selected but evenly distributed.
Derived randomElements(int n) const
Copy n elements from the container at random.
Generic sequential container with value semantics.
void push_back(const T &value)
Appends an element at the end of the sequence.
const_iterator cbegin() const
Returns const iterator at the beginning of the sequence.
void clear()
Removes all elements in the sequence.
const_iterator cend() const
Returns const iterator one past the end of the sequence.
static int samples()
Run the samples.
void topologicalSort(I begin, I end, F comparator)
Topological sorting algorithm.
void topologicallySortedInsert(C &container, T &&value, F comparator)
Insert an element into a sequential container while preserving the topological ordering of the contai...