klao@347
|
1 |
#include <iter_map.h>
|
klao@347
|
2 |
#include <maps.h>
|
klao@347
|
3 |
|
klao@347
|
4 |
#include <iostream>
|
klao@347
|
5 |
|
klao@347
|
6 |
using namespace hugo;
|
klao@347
|
7 |
using namespace std;
|
klao@347
|
8 |
|
klao@347
|
9 |
const int N = 3;
|
klao@347
|
10 |
|
klao@347
|
11 |
typedef StdMap<int,int> BaseMap;
|
klao@347
|
12 |
typedef IterableMap<BaseMap, N> TestMap;
|
klao@361
|
13 |
typedef IterableBoolMap<BaseMap> TestBoolMap;
|
klao@347
|
14 |
|
klao@347
|
15 |
|
klao@361
|
16 |
template<typename TM>
|
klao@361
|
17 |
void print(TM const& m, int N = 3) {
|
klao@347
|
18 |
cout << "Size of the map: " << m.size() << endl;
|
klao@347
|
19 |
for(int i=0; i<N; ++i) {
|
klao@347
|
20 |
cout << " Class " << i << ". (size=" << m.size(i) << "): " << flush;
|
klao@347
|
21 |
cout << " ";
|
klao@361
|
22 |
for(typename TM::iterator j = m.begin(i); j!=m.end(i); ++j) {
|
klao@347
|
23 |
cout << " " << *j;
|
klao@347
|
24 |
}
|
klao@347
|
25 |
cout << endl;
|
klao@347
|
26 |
}
|
klao@347
|
27 |
}
|
klao@347
|
28 |
|
klao@347
|
29 |
|
klao@347
|
30 |
|
klao@347
|
31 |
int main() {
|
klao@347
|
32 |
|
klao@361
|
33 |
{
|
klao@361
|
34 |
BaseMap base(344);
|
klao@361
|
35 |
TestMap test(base);
|
klao@347
|
36 |
|
klao@347
|
37 |
|
klao@361
|
38 |
print(test);
|
klao@347
|
39 |
|
klao@361
|
40 |
cout << "Inserting 12 to class 2...\n";
|
klao@361
|
41 |
test.insert(12,2);
|
klao@361
|
42 |
print(test);
|
klao@347
|
43 |
|
klao@347
|
44 |
|
klao@361
|
45 |
cout << "Inserting 22 to class 2...\n";
|
klao@361
|
46 |
test.insert(22,2);
|
klao@361
|
47 |
print(test);
|
klao@347
|
48 |
|
klao@361
|
49 |
cout << "Testing some map values:\n";
|
klao@361
|
50 |
cout << " 12: " << int(test[12]) << endl;
|
klao@347
|
51 |
|
klao@361
|
52 |
cout << "Inserting 10 to class 0...\n";
|
klao@361
|
53 |
test.insert(10,0);
|
klao@361
|
54 |
print(test);
|
klao@347
|
55 |
|
klao@361
|
56 |
cout << "Testing some map values:\n";
|
klao@361
|
57 |
cout << " 12: " << int(test[12]) << endl;
|
klao@347
|
58 |
|
klao@361
|
59 |
cout << "Inserting 11 to class 1...\n";
|
klao@361
|
60 |
test.insert(11,1);
|
klao@361
|
61 |
print(test);
|
klao@347
|
62 |
|
klao@361
|
63 |
cout << "Testing some map values:\n";
|
klao@361
|
64 |
cout << " 12: " << int(test[12]) << endl;
|
klao@361
|
65 |
cout << " 22: " << int(test[22]) << endl;
|
klao@361
|
66 |
cout << " 10: " << int(test[10]) << endl;
|
klao@361
|
67 |
cout << " 11: " << int(test[11]) << endl;
|
klao@361
|
68 |
cout << " 42: " << int(test[42]) << endl;
|
klao@347
|
69 |
|
klao@361
|
70 |
cout << "Inserting 21 to class 1...\n";
|
klao@361
|
71 |
test.insert(21,1);
|
klao@361
|
72 |
print(test);
|
klao@347
|
73 |
|
klao@361
|
74 |
cout << "Inserting 20 to class 1...\n";
|
klao@361
|
75 |
test.insert(20,0);
|
klao@361
|
76 |
print(test);
|
klao@347
|
77 |
|
klao@361
|
78 |
cout << "Testing some map values:\n";
|
klao@361
|
79 |
cout << " 12: " << int(test[12]) << endl;
|
klao@361
|
80 |
cout << " 22: " << int(test[22]) << endl;
|
klao@361
|
81 |
cout << " 10: " << int(test[10]) << endl;
|
klao@361
|
82 |
cout << " 20: " << int(test[20]) << endl;
|
klao@361
|
83 |
cout << " 11: " << int(test[11]) << endl;
|
klao@361
|
84 |
cout << " 21: " << int(test[21]) << endl;
|
klao@361
|
85 |
cout << " 42: " << int(test[42]) << endl;
|
klao@347
|
86 |
|
klao@361
|
87 |
cout << "Setting 20 to class 2...\n";
|
klao@361
|
88 |
test.set(20,2);
|
klao@361
|
89 |
print(test);
|
klao@347
|
90 |
|
klao@361
|
91 |
cout << "Setting 10 to class 1...\n";
|
klao@361
|
92 |
test.set(10,1);
|
klao@361
|
93 |
print(test);
|
klao@347
|
94 |
|
klao@361
|
95 |
cout << "Setting 11 to class 1...\n";
|
klao@361
|
96 |
test.set(11,1);
|
klao@361
|
97 |
print(test);
|
klao@347
|
98 |
|
klao@361
|
99 |
cout << "Setting 12 to class 1...\n";
|
klao@361
|
100 |
test.set(12,1);
|
klao@361
|
101 |
print(test);
|
klao@347
|
102 |
|
klao@361
|
103 |
cout << "Setting 21 to class 2...\n";
|
klao@361
|
104 |
test.set(21,2);
|
klao@361
|
105 |
print(test);
|
klao@347
|
106 |
|
klao@361
|
107 |
cout << "Setting 22 to class 2...\n";
|
klao@361
|
108 |
test.set(22,2);
|
klao@361
|
109 |
print(test);
|
klao@347
|
110 |
|
klao@361
|
111 |
cout << "Testing some map values:\n";
|
klao@361
|
112 |
cout << " 12: " << int(test[12]) << endl;
|
klao@361
|
113 |
cout << " 22: " << int(test[22]) << endl;
|
klao@361
|
114 |
cout << " 10: " << int(test[10]) << endl;
|
klao@361
|
115 |
cout << " 20: " << int(test[20]) << endl;
|
klao@361
|
116 |
cout << " 11: " << int(test[11]) << endl;
|
klao@361
|
117 |
cout << " 21: " << int(test[21]) << endl;
|
klao@361
|
118 |
cout << " 42: " << int(test[42]) << endl;
|
klao@361
|
119 |
}
|
klao@347
|
120 |
|
klao@361
|
121 |
{
|
klao@362
|
122 |
cout << "\n\n\nTesting the IterableBoolMap...\n";
|
klao@361
|
123 |
|
klao@361
|
124 |
BaseMap base(344);
|
klao@362
|
125 |
TestBoolMap test(base,true);
|
klao@361
|
126 |
|
klao@361
|
127 |
|
klao@361
|
128 |
print(test,2);
|
klao@361
|
129 |
|
klao@361
|
130 |
cout << "Inserting 12 to class true...\n";
|
klao@361
|
131 |
test.insert(12,true);
|
klao@361
|
132 |
print(test,2);
|
klao@361
|
133 |
|
klao@361
|
134 |
|
klao@361
|
135 |
cout << "Inserting 22 to class true...\n";
|
klao@361
|
136 |
test.insert(22,true);
|
klao@361
|
137 |
print(test,2);
|
klao@361
|
138 |
|
klao@361
|
139 |
cout << "Testing some map values:\n";
|
klao@361
|
140 |
cout << " 12: " << test[12] << endl;
|
klao@361
|
141 |
|
klao@361
|
142 |
cout << "Inserting 10 to class false...\n";
|
klao@361
|
143 |
test.insert(10,false);
|
klao@361
|
144 |
print(test,2);
|
klao@361
|
145 |
|
klao@361
|
146 |
cout << "Testing some map values:\n";
|
klao@361
|
147 |
cout << " 12: " << test[12] << endl;
|
klao@361
|
148 |
|
klao@361
|
149 |
cout << "Inserting 11 to class false...\n";
|
klao@361
|
150 |
test.insert(11,false);
|
klao@361
|
151 |
print(test,2);
|
klao@361
|
152 |
|
klao@361
|
153 |
cout << "Testing some map values:\n";
|
klao@361
|
154 |
cout << " 12: " << test[12] << endl;
|
klao@361
|
155 |
cout << " 22: " << test[22] << endl;
|
klao@361
|
156 |
cout << " 10: " << test[10] << endl;
|
klao@361
|
157 |
cout << " 11: " << test[11] << endl;
|
klao@361
|
158 |
cout << " 42: " << test[42] << endl;
|
klao@361
|
159 |
|
klao@362
|
160 |
cout << "Setting 10 to class true...\n";
|
klao@362
|
161 |
test.set(10,true);
|
klao@361
|
162 |
print(test,2);
|
klao@361
|
163 |
|
klao@362
|
164 |
cout << "Setting 11 to class true...\n";
|
klao@361
|
165 |
test.set(11,1);
|
klao@361
|
166 |
print(test,2);
|
klao@361
|
167 |
|
klao@362
|
168 |
cout << "Setting 12 to class false...\n";
|
klao@362
|
169 |
test.set(12,false);
|
klao@361
|
170 |
print(test,2);
|
klao@361
|
171 |
|
klao@362
|
172 |
cout << "Setting 22 to class false...\n";
|
klao@362
|
173 |
test.set(22,false);
|
klao@361
|
174 |
print(test,2);
|
klao@361
|
175 |
|
klao@361
|
176 |
cout << "Testing some map values:\n";
|
klao@361
|
177 |
cout << " 12: " << test[12] << endl;
|
klao@361
|
178 |
cout << " 22: " << test[22] << endl;
|
klao@361
|
179 |
cout << " 10: " << test[10] << endl;
|
klao@361
|
180 |
cout << " 11: " << test[11] << endl;
|
klao@361
|
181 |
cout << " 42: " << test[42] << endl;
|
klao@361
|
182 |
|
klao@361
|
183 |
}
|
klao@347
|
184 |
}
|