aboutsummaryrefslogtreecommitdiffstats
path: root/util/random/shuffle.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/random/shuffle.h
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/random/shuffle.h')
-rw-r--r--util/random/shuffle.h44
1 files changed, 22 insertions, 22 deletions
diff --git a/util/random/shuffle.h b/util/random/shuffle.h
index 274ac147c9..579f3073ee 100644
--- a/util/random/shuffle.h
+++ b/util/random/shuffle.h
@@ -1,43 +1,43 @@
#pragma once
-#include "fast.h"
-#include "entropy.h"
-
+#include "fast.h"
+#include "entropy.h"
+
#include <util/generic/utility.h>
-
-// some kind of https://en.wikipedia.org/wiki/Fisher–Yates_shuffle#The_modern_algorithm
-
-template <typename TRandIter, typename TRandIterEnd>
+
+// some kind of https://en.wikipedia.org/wiki/Fisher–Yates_shuffle#The_modern_algorithm
+
+template <typename TRandIter, typename TRandIterEnd>
inline void Shuffle(TRandIter begin, TRandIterEnd end) {
- static_assert(sizeof(end - begin) <= sizeof(size_t), "fixme");
- static_assert(sizeof(TReallyFastRng32::RandMax()) <= sizeof(size_t), "fixme");
-
- if ((size_t)(end - begin) < (size_t)TReallyFastRng32::RandMax()) {
- Shuffle(begin, end, TReallyFastRng32(Seed()));
- } else {
- Shuffle(begin, end, TFastRng64(Seed()));
+ static_assert(sizeof(end - begin) <= sizeof(size_t), "fixme");
+ static_assert(sizeof(TReallyFastRng32::RandMax()) <= sizeof(size_t), "fixme");
+
+ if ((size_t)(end - begin) < (size_t)TReallyFastRng32::RandMax()) {
+ Shuffle(begin, end, TReallyFastRng32(Seed()));
+ } else {
+ Shuffle(begin, end, TFastRng64(Seed()));
}
}
template <typename TRandIter, typename TRandIterEnd, typename TRandGen>
-inline void Shuffle(TRandIter begin, TRandIterEnd end, TRandGen&& gen) {
+inline void Shuffle(TRandIter begin, TRandIterEnd end, TRandGen&& gen) {
const size_t sz = end - begin;
for (size_t i = 1; i < sz; ++i) {
- DoSwap(*(begin + i), *(begin + gen.Uniform(i + 1)));
+ DoSwap(*(begin + i), *(begin + gen.Uniform(i + 1)));
}
}
template <typename TRange>
inline void ShuffleRange(TRange& range) {
- auto b = range.begin();
-
- Shuffle(b, range.end());
+ auto b = range.begin();
+
+ Shuffle(b, range.end());
}
template <typename TRange, typename TRandGen>
inline void ShuffleRange(TRange& range, TRandGen&& gen) {
- auto b = range.begin();
-
- Shuffle(b, range.end(), gen);
+ auto b = range.begin();
+
+ Shuffle(b, range.end(), gen);
}