diff options
author | George Hazan <george.hazan@gmail.com> | 2023-06-04 19:24:05 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-06-04 19:24:05 +0300 |
commit | efc336e60cf1331bf5f3213d296981b87b8b2a6c (patch) | |
tree | ea59ea1a324f45f6e8a06cc0887b376bfba90ca9 /protocols/Telegram/tdlib/td/tdutils/test/heap.cpp | |
parent | 6e83622d2af1cec3c759f4cff6efe4df2fe3328c (diff) |
fixes #3537 (Telegram: 32-разрядная версия падает в 64-разрядной Windows) + update to the fresh TDLIB
Diffstat (limited to 'protocols/Telegram/tdlib/td/tdutils/test/heap.cpp')
-rw-r--r-- | protocols/Telegram/tdlib/td/tdutils/test/heap.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/protocols/Telegram/tdlib/td/tdutils/test/heap.cpp b/protocols/Telegram/tdlib/td/tdutils/test/heap.cpp index 02b6d81424..43072fb97e 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-2022 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 // // 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) @@ -23,7 +23,7 @@ TEST(Heap, sort_random_perm) { v[i] = i; } td::Random::Xorshift128plus rnd(123); - td::random_shuffle(td::as_mutable_span(v), rnd); + td::rand_shuffle(td::as_mutable_span(v), rnd); td::vector<td::HeapNode> nodes(n); td::KHeap<int> kheap; for (int i = 0; i < n; i++) { @@ -46,10 +46,12 @@ class CheckedHeap { nodes[i].value = i; } } + 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); } + void check() const { for (auto p : set_heap) { std::fprintf(stderr, "(%d;%d)", p.first, p.second); @@ -59,13 +61,16 @@ class CheckedHeap { std::fprintf(stderr, "\n"); kheap.check(); } + int random_id() const { CHECK(!empty()); return ids[td::Random::fast(0, static_cast<int>(ids.size() - 1))]; } + std::size_t size() const { return ids.size(); } + bool empty() const { return ids.empty(); } @@ -77,8 +82,8 @@ class CheckedHeap { ASSERT_EQ(res, kheap.top_key()); return res; } + int insert(int key) { - // std::fprintf(stderr, "insert %d\n", key); int id; if (free_ids.empty()) { UNREACHABLE(); @@ -96,15 +101,15 @@ class CheckedHeap { set_heap.emplace(key, id); return id; } + void fix_key(int new_key, int id) { - // std::fprintf(stderr, "fix key %d %d (old_key = %d)\n", new_key, id, nodes[id].key); set_heap.erase(std::make_pair(nodes[id].key, id)); nodes[id].key = new_key; kheap.fix(new_key, &nodes[id]); set_heap.emplace(new_key, id); } + void erase(int id) { - // std::fprintf(stderr, "erase %d\n", id); int pos = rev_ids[id]; CHECK(pos != -1); ids[pos] = ids.back(); @@ -116,8 +121,8 @@ class CheckedHeap { kheap.erase(&nodes[id]); set_heap.erase(std::make_pair(nodes[id].key, id)); } + void pop() { - // std::fprintf(stderr, "pop\n"); CHECK(!empty()); Node *node = static_cast<Node *>(kheap.pop()); int id = node->value; |