summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/tdutils/test/heap.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-11-30 17:48:47 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-11-30 17:48:47 +0300
commit0ece30dc7c0e34b4c5911969b8fa99c33c6d023c (patch)
tree671325d3fec09b999411e4e3ab84ef8259261818 /protocols/Telegram/tdlib/td/tdutils/test/heap.cpp
parent46c53ffc6809c67e4607e99951a2846c382b63b2 (diff)
Telegram: update for TDLIB
Diffstat (limited to 'protocols/Telegram/tdlib/td/tdutils/test/heap.cpp')
-rw-r--r--protocols/Telegram/tdlib/td/tdutils/test/heap.cpp47
1 files changed, 21 insertions, 26 deletions
diff --git a/protocols/Telegram/tdlib/td/tdutils/test/heap.cpp b/protocols/Telegram/tdlib/td/tdutils/test/heap.cpp
index 0dcfcf98ff..02b6d81424 100644
--- a/protocols/Telegram/tdlib/td/tdutils/test/heap.cpp
+++ b/protocols/Telegram/tdlib/td/tdutils/test/heap.cpp
@@ -1,5 +1,5 @@
//
-// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
+// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -8,29 +8,24 @@
#include "td/utils/common.h"
#include "td/utils/Heap.h"
-#include "td/utils/logging.h"
#include "td/utils/Random.h"
+#include "td/utils/Span.h"
-#include <algorithm>
#include <cstdio>
-#include <cstdlib>
#include <set>
#include <utility>
-REGISTER_TESTS(heap)
-
-using namespace td;
-
TEST(Heap, sort_random_perm) {
int n = 1000000;
- std::vector<int> v(n);
+
+ td::vector<int> v(n);
for (int i = 0; i < n; i++) {
v[i] = i;
}
- std::srand(123);
- std::random_shuffle(v.begin(), v.end());
- std::vector<HeapNode> nodes(n);
- KHeap<int> kheap;
+ td::Random::Xorshift128plus rnd(123);
+ 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++) {
kheap.insert(v[i], &nodes[i]);
}
@@ -38,7 +33,7 @@ TEST(Heap, sort_random_perm) {
ASSERT_EQ(i, kheap.top_key());
kheap.pop();
}
-};
+}
class CheckedHeap {
public:
@@ -51,7 +46,7 @@ class CheckedHeap {
nodes[i].value = i;
}
}
- static void xx(int key, const HeapNode *heap_node) {
+ static void xx(int key, const td::HeapNode *heap_node) {
const Node *node = static_cast<const Node *>(heap_node);
std::fprintf(stderr, "(%d;%d)", node->key, node->value);
}
@@ -66,9 +61,9 @@ class CheckedHeap {
}
int random_id() const {
CHECK(!empty());
- return ids[Random::fast(0, static_cast<int>(ids.size() - 1))];
+ return ids[td::Random::fast(0, static_cast<int>(ids.size() - 1))];
}
- size_t size() const {
+ std::size_t size() const {
return ids.size();
}
bool empty() const {
@@ -140,19 +135,19 @@ class CheckedHeap {
}
private:
- struct Node : public HeapNode {
+ struct Node final : public td::HeapNode {
Node() = default;
Node(int key, int value) : key(key), value(value) {
}
int key = 0;
int value = 0;
};
- vector<int> ids;
- vector<int> rev_ids;
- vector<int> free_ids;
- vector<Node> nodes;
+ td::vector<int> ids;
+ td::vector<int> rev_ids;
+ td::vector<int> free_ids;
+ td::vector<Node> nodes;
std::set<std::pair<int, int>> set_heap;
- KHeap<int> kheap;
+ td::KHeap<int> kheap;
};
TEST(Heap, random_events) {
@@ -163,11 +158,11 @@ TEST(Heap, random_events) {
heap.top_key();
}
- int x = Random::fast(0, 4);
+ int x = td::Random::fast(0, 4);
if (heap.empty() || (x < 2 && heap.size() < 1000)) {
- heap.insert(Random::fast(0, 99));
+ heap.insert(td::Random::fast(0, 99));
} else if (x < 3) {
- heap.fix_key(Random::fast(0, 99), heap.random_id());
+ heap.fix_key(td::Random::fast(0, 99), heap.random_id());
} else if (x < 4) {
heap.erase(heap.random_id());
} else if (x < 5) {