diff options
Diffstat (limited to 'tdutils')
| -rw-r--r-- | tdutils/td/utils/Random.h | 10 | ||||
| -rw-r--r-- | tdutils/td/utils/tests.h | 9 | ||||
| -rw-r--r-- | tdutils/test/ChainScheduler.cpp | 2 | ||||
| -rw-r--r-- | tdutils/test/hashset_benchmark.cpp | 2 | ||||
| -rw-r--r-- | tdutils/test/heap.cpp | 2 |
5 files changed, 13 insertions, 12 deletions
diff --git a/tdutils/td/utils/Random.h b/tdutils/td/utils/Random.h index b2d9cc18a..cae927704 100644 --- a/tdutils/td/utils/Random.h +++ b/tdutils/td/utils/Random.h @@ -8,6 +8,7 @@ #include "td/utils/common.h" #include "td/utils/Slice.h" +#include "td/utils/Span.h" #include <utility> @@ -37,6 +38,15 @@ class Random { } #endif + template <class T, class R> + static void shuffle(MutableSpan<T> v, R &rnd) { + for (size_t i = 1; i < v.size(); i++) { + auto pos = static_cast<size_t>(rnd()) % (i + 1); + using std::swap; + swap(v[i], v[pos]); + } + } + static uint32 fast_uint32(); static uint64 fast_uint64(); diff --git a/tdutils/td/utils/tests.h b/tdutils/td/utils/tests.h index d89c4c6ae..dd70678c2 100644 --- a/tdutils/td/utils/tests.h +++ b/tdutils/td/utils/tests.h @@ -167,15 +167,6 @@ string rand_string(int from, int to, size_t len); vector<string> rand_split(Slice str); -template <class T, class R> -void rand_shuffle(MutableSpan<T> v, R &rnd) { - for (size_t i = 1; i < v.size(); i++) { - auto pos = static_cast<size_t>(rnd()) % (i + 1); - using std::swap; - swap(v[i], v[pos]); - } -} - template <class T1, class T2> void assert_eq_impl(const T1 &expected, const T2 &received, const char *file, int line) { LOG_CHECK(expected == received) << tag("expected", expected) << tag("received", received) << " in " << file diff --git a/tdutils/test/ChainScheduler.cpp b/tdutils/test/ChainScheduler.cpp index 782106a88..c41559e20 100644 --- a/tdutils/test/ChainScheduler.cpp +++ b/tdutils/test/ChainScheduler.cpp @@ -139,7 +139,7 @@ TEST(ChainScheduler, Stress) { int chain_n = rnd.fast(1, ChainsN); td::vector<ChainId> chain_ids(ChainsN); std::iota(chain_ids.begin(), chain_ids.end(), 1); - td::rand_shuffle(td::as_mutable_span(chain_ids), rnd); + td::Random::shuffle(td::as_mutable_span(chain_ids), rnd); chain_ids.resize(chain_n); for (auto chain_id : chain_ids) { chains[td::narrow_cast<size_t>(chain_id)].push_back(query); diff --git a/tdutils/test/hashset_benchmark.cpp b/tdutils/test/hashset_benchmark.cpp index a5039a8d0..ed53468bd 100644 --- a/tdutils/test/hashset_benchmark.cpp +++ b/tdutils/test/hashset_benchmark.cpp @@ -205,7 +205,7 @@ static void BM_Get(benchmark::State &state) { } std::size_t key_i = 0; - td::rand_shuffle(td::as_mutable_span(keys), rnd); + td::Random::shuffle(td::as_mutable_span(keys), rnd); auto next_key = [&] { key_i++; if (key_i == data.size()) { diff --git a/tdutils/test/heap.cpp b/tdutils/test/heap.cpp index 99ea2c55e..887963c7f 100644 --- a/tdutils/test/heap.cpp +++ b/tdutils/test/heap.cpp @@ -23,7 +23,7 @@ TEST(Heap, sort_random_perm) { v[i] = i; } td::Random::Xorshift128plus rnd(123); - td::rand_shuffle(td::as_mutable_span(v), rnd); + td::Random::shuffle(td::as_mutable_span(v), rnd); td::vector<td::HeapNode> nodes(n); td::KHeap<int> kheap; for (int i = 0; i < n; i++) { |
