-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
106 lines (100 loc) · 2.44 KB
/
Copy pathmain.cpp
File metadata and controls
106 lines (100 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <filesystem>
#include <fstream>
#include <iostream>
#include <math.h>
#include <unordered_map>
#include <chrono>
#include <vector>
#include "include/leftist_heap.h"
#include "include/rp_heap.h"
namespace fs = std::filesystem;
class Timer {
std::chrono::time_point<std::chrono::system_clock> begin;
std::chrono::time_point<std::chrono::system_clock> end;
public:
void startTimer() {
begin = std::chrono::high_resolution_clock::now();;
}
void endTimer() {
end = std::chrono::high_resolution_clock::now();
}
float getElapsedTime() {
std::chrono::duration<float> diff = end - begin;
return diff.count();
}
};
void rpheap(auto path) {
std::ifstream cin(path);
int q, val, n;
RP::Node *nod;
cin >> n >> q;
std::vector<RP::rp_heap> h(n+3);
for(int i = 1; i <= q; i ++)
{
int cer;
cin >> cer;
if(cer == 1)
{
int m, val;
cin >> m >> val;
h[m].push(-val);
}
else if(cer == 2)
{
int m;
cin >> m;
// cout << -h[m].top() << "\n";
h[m].pop();
}
else
{
int a, b;
cin >> a >> b;
h[a].merge(h[b]);
}
}
cin.close();
}
void leftistHeap(auto path) {
std::ifstream cin(path);
int n, q;
cin>>n>>q;
std::vector<Leftist::leftist_heap> heaps(n+3);
while (q--) {
int c;
cin>>c;
if (c==1) {
int m,x;
cin>>m>>x;
heaps[m].insert(x);
}else if (c==2) {
int m;
cin>>m;
//g<<heaps[m].findMin()<<"\n";
heaps[m].deleteMin();
}else {
int a,b;
cin>>a>>b;
heaps[a].Merge(heaps[b]);
heaps[b].makeEmpty();
}
}
}
int main() {
std::string path = "../tests";
std::cout << "CWD: " << fs::current_path() << "\n";
for (const auto & entry : fs::directory_iterator(path)) {
std::ifstream cin(entry.path());
Timer t;
std::cout << entry.path() << std::endl;
t.startTimer();
leftistHeap(entry.path());
t.endTimer();
std::cout << "leftist-heap: " << t.getElapsedTime() << std::endl;
t.startTimer();
rpheap(entry.path());
t.endTimer();
std::cout <<"rank-pairing-heap: " << t.getElapsedTime() << std::endl;
}
return 0;
}