-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (50 loc) · 2.18 KB
/
main.cpp
File metadata and controls
57 lines (50 loc) · 2.18 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
#include <map>
#include <string>
#include <chrono>
#include <cassert>
#include "ChainingHash.h"
#include "ProbingHash.h"
#include <iostream>
#include <fstream>
void testHash(Hash<int, int> *hash, std::ofstream &myfile)
{
myfile << "current size: " << hash->size() << " bucket count: " << hash->bucket_count()
<< " load factor: " << hash->load_factor() << std::endl;
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
for (int i = 0; i < 100000; ++i)
{
assert(hash->insert(std::make_pair(i, i)));
}
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
myfile << "Time difference = " << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() << "[ms]" << std::endl;
begin = std::chrono::steady_clock::now();
assert((*hash)[97] == 97);
end = std::chrono::steady_clock::now();
myfile << "Time difference = " << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() << "[ms]" << std::endl;
begin = std::chrono::steady_clock::now();
hash->erase(97);
end = std::chrono::steady_clock::now();
myfile << "Time difference = " << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() << "[ms]" << std::endl;
begin = std::chrono::steady_clock::now();
assert((*hash)[10000] == 10000);
end = std::chrono::steady_clock::now();
myfile << "Time difference = " << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() << "[ms]" << std::endl;
myfile << "current size: " << hash->size() << " bucket count: " << hash->bucket_count()
<< " load factor: " << hash->load_factor() << std::endl;
hash->clear();
}
int main(int argc, char *argv[])
{
std::ofstream myfile;
myfile.open("output.txt");
// Added error report if can't open the file.
if (!outputFile.is_open()) {
std::cerr << "Failed to open output.txt for writing." << std::endl;
return 1;
}
ChainingHash<int, int> cHash(101);
ProbingHash<int, int> pHash(101);
testHash(&cHash, myfile);
testHash(&pHash, myfile);
myfile.close();
}