COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/klao/iter_map_test.cc @ 349:42c660f58702

Last change on this file since 349:42c660f58702 was 347:e4ab32225f1c, checked in by Mihaly Barasz, 18 years ago

A generic map with value type [0, N) where N is a small integer.
Can enumerate keys with a given value.

File size: 2.6 KB
Line 
1#include <iter_map.h>
2#include <maps.h>
3
4#include <iostream>
5
6using namespace hugo;
7using namespace std;
8
9const int N = 3;
10
11typedef StdMap<int,int> BaseMap;
12typedef IterableMap<BaseMap, N> TestMap;
13
14
15void print(TestMap const& m) {
16  cout << "Size of the map: " << m.size() << endl;
17  for(int i=0; i<N; ++i) {
18    cout << "  Class " << i << ". (size=" << m.size(i) << "): " << flush;
19    cout << "    ";
20    for(TestMap::iterator j = m.begin(i); j!=m.end(i); ++j) {
21      cout << " " << *j;
22    }
23    cout << endl;
24  }
25}
26
27
28
29int main() {
30
31  BaseMap base(344);
32  TestMap test(base);
33
34
35  print(test);
36
37  cout << "Inserting 12 to class 2...\n";
38  test.insert(12,2);
39  print(test);
40
41
42  cout << "Inserting 22 to class 2...\n";
43  test.insert(22,2);
44  print(test);
45
46  cout << "Testing some map values:\n";
47  cout << " 12: " << int(test[12]) << endl;
48
49  cout << "Inserting 10 to class 0...\n";
50  test.insert(10,0);
51  print(test);
52
53  cout << "Testing some map values:\n";
54  cout << " 12: " << int(test[12]) << endl;
55
56  cout << "Inserting 11 to class 1...\n";
57  test.insert(11,1);
58  print(test);
59
60  cout << "Testing some map values:\n";
61  cout << " 12: " << int(test[12]) << endl;
62  cout << " 22: " << int(test[22]) << endl;
63  cout << " 10: " << int(test[10]) << endl;
64  cout << " 11: " << int(test[11]) << endl;
65  cout << " 42: " << int(test[42]) << endl;
66
67  cout << "Inserting 21 to class 1...\n";
68  test.insert(21,1);
69  print(test);
70
71  cout << "Inserting 20 to class 1...\n";
72  test.insert(20,0);
73  print(test);
74
75  cout << "Testing some map values:\n";
76  cout << " 12: " << int(test[12]) << endl;
77  cout << " 22: " << int(test[22]) << endl;
78  cout << " 10: " << int(test[10]) << endl;
79  cout << " 20: " << int(test[20]) << endl;
80  cout << " 11: " << int(test[11]) << endl;
81  cout << " 21: " << int(test[21]) << endl;
82  cout << " 42: " << int(test[42]) << endl;
83
84  cout << "Setting 20 to class 2...\n";
85  test.set(20,2);
86  print(test);
87 
88  cout << "Setting 10 to class 1...\n";
89  test.set(10,1);
90  print(test);
91 
92  cout << "Setting 11 to class 1...\n";
93  test.set(11,1);
94  print(test);
95 
96  cout << "Setting 12 to class 1...\n";
97  test.set(12,1);
98  print(test);
99 
100  cout << "Setting 21 to class 2...\n";
101  test.set(21,2);
102  print(test);
103 
104  cout << "Setting 22 to class 2...\n";
105  test.set(22,2);
106  print(test);
107 
108  cout << "Testing some map values:\n";
109  cout << " 12: " << int(test[12]) << endl;
110  cout << " 22: " << int(test[22]) << endl;
111  cout << " 10: " << int(test[10]) << endl;
112  cout << " 20: " << int(test[20]) << endl;
113  cout << " 11: " << int(test[11]) << endl;
114  cout << " 21: " << int(test[21]) << endl;
115  cout << " 42: " << int(test[42]) << endl;
116
117}
Note: See TracBrowser for help on using the repository browser.