-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
132 lines (120 loc) · 3.36 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
#include <iostream>
#include <vector>
using namespace std;
#include "HashTable.hpp"
void operatorWithDelHashtable(HashTable<string>& ht) {
ht.ht_print();
ht.ht_del("11");
ht.ht_del("22");
ht.ht_del("ab");
ht.ht_del("bc");
ht.ht_print();
ht.ht_del("c9");
ht.ht_print();
ht.ht_del("c8");
ht.ht_print();
ht.ht_del("c7");
ht.ht_print();
ht.ht_del("c6");
ht.ht_print();
ht.ht_del("c5");
ht.ht_print();
ht.ht_del("c4");
ht.ht_print();
ht.ht_del("c3");
ht.ht_print();
ht.ht_del("c2");
ht.ht_print();
}
void operatorWithHashtable(HashTable<string>& ht) {
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("11", "11");
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("22", "22");
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("11", "11a");
ht.ht_print();
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("ab", "ab");
ht.ht_print();
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("bc", "bc");
ht.ht_print();
ht.ht_insert("mybrujmaonutk", "11");
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("c9", "c9");
ht.ht_print();
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("c8", "c8");
ht.ht_print();
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("c7", "c7");
ht.ht_print();
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("c6", "c6");
ht.ht_print();
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("c5", "c5");
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("c4", "c4");
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("c3", "c3");
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("c2", "c2");
cout << "++++++++++++++++++++++" << endl;
ht.ht_insert("c1", "c1");
cout << "++++++++++++++++++++++" << endl;
ht.ht_print();
cout << "======end insert" << endl;
string* value = ht.ht_search("11");
cout << "value11: " << value << endl;
value = ht.ht_search("22");
cout << "value22: " << value << endl;
cout << "------going to delete" << endl;
operatorWithDelHashtable(ht);
cout << "------end delete" << endl;
}
void test_string() {
cout << "start." << endl;
HashTable<string>& ht = HashTable<string>::ht_new();
operatorWithHashtable(ht);
ht.ht_destroy();
cout << "end" << endl;
}
class ObjectA {
public:
ObjectA(uint32_t age, uint32_t height, string name): age_(age), height_(height), name_(name) {
}
friend ostream& operator<<(ostream& out, ObjectA& o);
private:
uint32_t age_;
uint32_t height_;
string name_;
};
ostream& operator<<(ostream& out, ObjectA& o) {
out << "age: " << o.age_ << ", height: " << o.height_ << ", name: " << o.name_;
return out;
}
void test_model() {
cout << "start." << endl;
HashTable<ObjectA>& ht = HashTable<ObjectA>::ht_new();
ht.ht_insert("aker", ObjectA{32, 180, "aker"});
ht.ht_print();
ht.ht_destroy();
cout << "end" << endl;
}
void test_charx() {
cout << "start." << endl;
HashTable<char*>& ht = HashTable<char*>::ht_new();
ht.ht_insert("aker", "akerdi");
ht.ht_print();
ht.ht_destroy();
cout << "end" << endl;
}
int main(int argc, char** argv) {
cout.setf(ios::unitbuf);
test_string();
test_model();
test_charx();
return 0;
}