|
|
|
@ -3,20 +3,20 @@
|
|
|
|
|
#include <rng.h>
|
|
|
|
|
#include <reinterpret.h>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <fmt/format.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
namespace rng {
|
|
|
|
|
template<typename T, typename R>
|
|
|
|
|
inline void shuffle(R& rng, span<T> span)
|
|
|
|
|
{
|
|
|
|
|
if(!span.size()) return;
|
|
|
|
|
fmt::print(" -> shuffling {} objects...", span.size());
|
|
|
|
|
std::cout << " -> shuffling " << span.size() << " objects...";
|
|
|
|
|
for(std::size_t i=span.size()-1;i>0;i--)
|
|
|
|
|
{
|
|
|
|
|
auto j = rng.next_long(i);
|
|
|
|
|
std::swap(span[i], span[j]);
|
|
|
|
|
}
|
|
|
|
|
fmt::print(" OK\n");
|
|
|
|
|
std::cout << " OK" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename R>
|
|
|
|
@ -25,7 +25,7 @@ namespace rng {
|
|
|
|
|
if(!span.size()) return;
|
|
|
|
|
std::vector<std::size_t> rng_values(span.size());
|
|
|
|
|
|
|
|
|
|
fmt::print(" -> unshuffling {} objects...", span.size());
|
|
|
|
|
std::cout << " -> unshuffling " << span.size() << " objects...";
|
|
|
|
|
for(std::size_t i=span.size()-1;i>0;i--)
|
|
|
|
|
rng_values.push_back(rng.next_long(i));
|
|
|
|
|
|
|
|
|
@ -33,6 +33,6 @@ namespace rng {
|
|
|
|
|
std::swap(span[i], span[rng_values.back()]);
|
|
|
|
|
rng_values.pop_back();
|
|
|
|
|
}
|
|
|
|
|
fmt::print(" OK\n");
|
|
|
|
|
std::cout << " OK" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|