-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashTable.cpp
122 lines (102 loc) · 3.29 KB
/
HashTable.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
/***************************************************************************
The Base Framework (Test Suite)
A framework for developing platform independent applications
See COPYRIGHT.txt for details.
This framework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
For the licensing terms refer to the file 'LICENSE'.
***************************************************************************/
#include <base/Application.h>
#include <base/collection/HashTable.h>
using namespace com::azure::dev::base;
class HashTableApplication : public Application {
private:
static const unsigned int MAJOR_VERSION = 1;
static const unsigned int MINOR_VERSION = 0;
public:
HashTableApplication()
: Application("HashTable")
{
}
void main()
{
fout << getFormalName() << " version "
<< MAJOR_VERSION << '.' << MINOR_VERSION << EOL
<< "The Base Framework (Test Suite)" << EOL
<< ENDL;
fout << "Initializing map" << ENDL;
HashTable<int, int> mii;
fout << "Adding associations to map ((2,2), (4,3), and (3,4))" << ENDL;
mii.add(2, 2);
mii.add(4, 3);
mii.add(3, 4);
fout << "mii: " << mii << ENDL;
fout << "size: " << mii.getSize() << ENDL;
{
fout << "Modifying enumeration of values of map (multiply by 3)" << ENDL;
HashTable<int, int>::ValueEnumerator enu = mii.getValueEnumerator();
while (enu.hasNext()) {
enu.next() *= 3;
}
fout << "mii: " << mii << ENDL;
}
{
fout << "Non-modifying enumeration of map (calculate sum of values)" << ENDL;
HashTable<int, int>::ReadEnumerator enu = mii.getReadEnumerator();
int sum = 0;
while (enu.hasNext()) {
sum += enu.next().getValue();
}
fout << "sum: " << sum << ENDL;
}
fout << "Adding associations to map ((1,6), (2,5), (4,2), and (5,1))" << ENDL;
mii.add(1, 6);
mii.add(2, 5);
mii.add(4, 2);
mii.add(5, 1);
fout << "mii: " << mii << ENDL;
fout << "Removing associations from map (4 and 3)" << ENDL;
mii.remove(4);
mii.remove(3);
fout << "mii: " << mii << ENDL;
fout << "Size: " << mii.getSize() << ENDL;
fout << "Removing all associations from the map" << ENDL;
mii.removeAll();
fout << "Size: " << mii.getSize() << ENDL;
static const Literal WORDS[] = {
MESSAGE("hi"),
MESSAGE("hello"),
MESSAGE("world"),
MESSAGE("the"),
MESSAGE("base"),
MESSAGE("framework"),
MESSAGE("word"),
MESSAGE("this"),
MESSAGE("keyword"),
MESSAGE("here"),
MESSAGE("other"),
MESSAGE("other2"),
MESSAGE("other3"),
MESSAGE("otsdfgher"),
MESSAGE("ofdgther2"),
MESSAGE("othergf3343"),
MESSAGE("othdfer"),
MESSAGE("otdher2"),
MESSAGE("otherd3"),
MESSAGE("otce2her"),
MESSAGE("othdF"),
MESSAGE("o23th"),
MESSAGE("a"),
MESSAGE("b"),
MESSAGE("c"),
MESSAGE("0")
};
HashTable<String, int> hashTable;
for (unsigned int i = 0; i < getArraySize(WORDS); ++i) {
hashTable.add(WORDS[i], WORDS[i].getLength());
}
fout << hashTable << ENDL;
}
};
APPLICATION_STUB(HashTableApplication);