-
Notifications
You must be signed in to change notification settings - Fork 21
/
hashMain_v2.cpp
40 lines (34 loc) · 1.04 KB
/
hashMain_v2.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
//
// Created by light on 19-10-20.
//
#include "hash_v2.h"
#include <vector>
#include <cstring>
enum { _S_n_primes = sizeof(unsigned long) != 8 ? 256 : 256 + 48 };
int main() {
vector<string> words{"java", "c++", "c", "c++", "c#", "python", "ruby", "python",
"c", "c", "c++", "java", "c++", "rust", "python"};
HashTable<string, int> ht;
for (string word : words) {
if (ht.contains(word)) {
ht.set(word, ht.get(word) + 1);
} else {
ht.add(word, 1);
}
}
cout<<ht;
cout<<"size="<<ht.getSize()<<",maxCapacity="<<ht.maxCapacity()<<",minCapacity="<<ht.minCapacity()<<endl;
string w="c++";
ht.remove(w);
if (ht.contains(w))
cout << "" << w << ": " << ht.get(w) << endl;
else
cout << "No word " << w << " in words" << endl;
cout<<ht;
ht.remove("c#");
ht.remove("java");
ht.remove("c");
cout<<"size="<<ht.getSize()<<",maxCapacity="<<ht.maxCapacity()<<",minCapacity="<<ht.minCapacity()<<endl;
cout<<ht;
return 0;
}