-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
140 lines (98 loc) · 3.18 KB
/
main.cpp
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
#include "include/eht.h"
#include "include/coarse-eth.h"
#include "include/fine-eth.h"
#include "lib/comparator/int-comparator.h"
#include "tools/lf_bench.hpp"
#define ASSERT_TRUE(condition) assert(condition)
#define ASSERT_FALSE(condition) assert(!condition)
#define ASSERT_EQ(val1, val2) assert(val1 == val2)
#define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
using namespace eht;
int main() {
auto hash_fn = HashFunction<int>();
auto cmp = IntComparator();
auto eht = CoarseEHT<int, int, IntComparator>("tools", cmp, hash_fn);
int num_keys = 8;
// insert some values
for (int i = 0; i < num_keys; i++) {
bool inserted = eht.Insert(i, i);
assert(inserted);
auto res = eht.Get(i);
assert(i == *res);
}
num_keys = 10;
auto eht2 = CoarseEHT<int, int, IntComparator>("tools", cmp, hash_fn);
// insert some values
for (int i = 0; i < num_keys; i++) {
bool inserted = eht2.Insert(i, i);
ASSERT_TRUE(inserted);
auto res = eht2.Get(i);
ASSERT_EQ(i, *res);
}
for (int i = 1 << 30; i < num_keys + (1 << 30); i++) {
bool inserted = eht2.Insert(i, i);
ASSERT_TRUE(inserted);
auto res =
eht2.Get(i);
ASSERT_EQ(i, *res);
}
// check that they were actually inserted
for (int i = 0; i < num_keys; i++) {
auto res = eht2.Get(i);
ASSERT_EQ(i, *res);
}
for (int i = 1 << 30; i < num_keys + (1 << 30); i++) {
auto res = eht2.Get(i);
ASSERT_TRUE(res.has_value());
ASSERT_EQ(i, *res);
}
// try to get some keys that don't exist/were not inserted
for (int i = num_keys; i < 2 * num_keys; i++) {
auto res = eht2.Get(i);
ASSERT_FALSE(res.has_value());
}
auto eht3 = FineEHT<int, int, IntComparator>("test3", cmp, hash_fn);
num_keys = 8;
// insert some values
for (int i = 0; i < num_keys; i++) {
bool inserted = eht3.Insert(i, i);
assert(inserted);
auto res = eht3.Get(i);
assert(i == *res);
}
num_keys = 10;
auto eht4 = FineEHT<int, int, IntComparator>("test4", cmp, hash_fn);
// insert some values
for (int i = 0; i < num_keys; i++) {
bool inserted = eht4.Insert(i, i);
ASSERT_TRUE(inserted);
auto res = eht4.Get(i);
ASSERT_EQ(i, *res);
}
for (int i = 1 << 30; i < num_keys + (1 << 30); i++) {
bool inserted = eht4.Insert(i, i);
ASSERT_TRUE(inserted);
auto res =
eht4.Get(i);
ASSERT_EQ(i, *res);
}
// check that they were actually inserted
for (int i = 0; i < num_keys; i++) {
auto res = eht4.Get(i);
ASSERT_EQ(i, *res);
}
for (int i = 1 << 30; i < num_keys + (1 << 30); i++) {
auto res = eht4.Get(i);
ASSERT_TRUE(res.has_value());
ASSERT_EQ(i, *res);
}
// try to get some keys that don't exist/were not inserted
for (int i = num_keys; i < 2 * num_keys; i++) {
auto res = eht4.Get(i);
ASSERT_FALSE(res.has_value());
}
std::cout << "All tests passed!" << std::endl;
lf_bench();
return 0;
}