-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathht-test.cpp
48 lines (47 loc) · 1.29 KB
/
ht-test.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
#include "ht.h"
#include "hash.h"
#include <unordered_map>
#include <iostream>
#include <utility>
#include <string>
#include <sstream>
#include <functional>
using namespace std;
int main()
{
DoubleHashProber<std::string, MyStringHash > dh;
HashTable<
std::string,
int,
DoubleHashProber<std::string, MyStringHash >,
std::hash<std::string>,
std::equal_to<std::string> > ht(0.7, dh);
// This is just arbitrary code. Change it to test whatever you like about your
// hash table implementation.
for(size_t i = 0; i < 10; i++){
std::stringstream ss;
ss << "hi" << i;
ht.insert({ss.str(), i});
}
if( ht.find("hi1") != nullptr ){
cout << "Found hi1" << endl;
ht["hi1"] += 1;
cout << "Incremented hi1's value to: " << ht["hi1"] << endl;
}
if( ht.find("doesnotexist") == nullptr ){
cout << "Did not find: doesnotexist" << endl;
}
cout << "HT size: " << ht.size() << endl;
ht.remove("hi7");
ht.remove("hi9");
cout << "HT size: " << ht.size() << endl;
if( ht.find("hi9") != nullptr ){
cout << "Found hi9" << endl;
}
else {
cout << "Did not find hi9" << endl;
}
ht.insert({"hi7",17});
cout << "size: " << ht.size() << endl;
return 0;
}