Commit 1879cfe7 authored by Xavier Thompson's avatar Xavier Thompson

rt/examples: Improve shuffle examples

parent 6a9a9562
......@@ -7,7 +7,21 @@
using u32 = std::uint_fast32_t;
u32 N = u32(1) << 26;
u32 N = u32(1) << 28;
long C = N >> 10;
template <typename RandomIt>
void sequential_shuffle(RandomIt first, RandomIt last)
{
auto it = first;
for (; it < last; it += C) {
std::shuffle(it, it + C, std::mt19937{std::random_device{}()});
}
if (it < last)
{
std::shuffle(it, last, std::mt19937{std::random_device{}()});
}
}
int main() {
std::vector<u32> v;
......@@ -15,7 +29,7 @@ int main() {
for (u32 i = 0; i < N; i++) {
v.push_back(i);
}
std::shuffle(v.begin(), v.end(), std::mt19937{std::random_device{}()});
sequential_shuffle(v.begin(), v.end());
printf("v[0] = %lu\n", v[0]);
puts("done");
}
......@@ -8,8 +8,8 @@
using namespace typon;
long N = 1 << 26;
long C = N >> 8;
long N = 1 << 28;
long C = N >> 10;
template <typename RandomIt>
Task<void> shuffle(RandomIt first, RandomIt last)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment