Do not use namespace td in KHeap test.
GitOrigin-RevId: 7f342ada1a91791c1c64184d7a070bccfb2eed12
This commit is contained in:
parent
ecd8b3b6ce
commit
4eed84132e
@ -16,23 +16,21 @@
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// random shuffle
|
||||
for (int i = 1; i < n; i++) {
|
||||
std::swap(v[Random::fast(0, i)], v[i]);
|
||||
std::swap(v[td::Random::fast(0, i)], v[i]);
|
||||
}
|
||||
|
||||
std::vector<HeapNode> nodes(n);
|
||||
KHeap<int> kheap;
|
||||
td::vector<td::HeapNode> nodes(n);
|
||||
td::KHeap<int> kheap;
|
||||
for (int i = 0; i < n; i++) {
|
||||
kheap.insert(v[i], &nodes[i]);
|
||||
}
|
||||
@ -53,7 +51,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);
|
||||
}
|
||||
@ -68,9 +66,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 {
|
||||
@ -142,19 +140,19 @@ class CheckedHeap {
|
||||
}
|
||||
|
||||
private:
|
||||
struct Node : public HeapNode {
|
||||
struct Node : 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) {
|
||||
@ -165,11 +163,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) {
|
||||
|
Reference in New Issue
Block a user