src/work/klao/iter_map_test.cc
author alpar
Sat, 17 Apr 2004 13:15:53 +0000
changeset 348 b63ea19e502e
child 361 ab0899df30d2
permissions -rw-r--r--
A bool Edge Map with iterators that goes through the true or the false edges.
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@347
    13
klao@347
    14
klao@347
    15
void print(TestMap const& m) {
klao@347
    16
  cout << "Size of the map: " << m.size() << endl;
klao@347
    17
  for(int i=0; i<N; ++i) {
klao@347
    18
    cout << "  Class " << i << ". (size=" << m.size(i) << "): " << flush;
klao@347
    19
    cout << "    ";
klao@347
    20
    for(TestMap::iterator j = m.begin(i); j!=m.end(i); ++j) {
klao@347
    21
      cout << " " << *j;
klao@347
    22
    }
klao@347
    23
    cout << endl;
klao@347
    24
  }
klao@347
    25
}
klao@347
    26
klao@347
    27
klao@347
    28
klao@347
    29
int main() {
klao@347
    30
klao@347
    31
  BaseMap base(344);
klao@347
    32
  TestMap test(base);
klao@347
    33
klao@347
    34
klao@347
    35
  print(test);
klao@347
    36
klao@347
    37
  cout << "Inserting 12 to class 2...\n";
klao@347
    38
  test.insert(12,2);
klao@347
    39
  print(test);
klao@347
    40
klao@347
    41
klao@347
    42
  cout << "Inserting 22 to class 2...\n";
klao@347
    43
  test.insert(22,2);
klao@347
    44
  print(test);
klao@347
    45
klao@347
    46
  cout << "Testing some map values:\n";
klao@347
    47
  cout << " 12: " << int(test[12]) << endl;
klao@347
    48
klao@347
    49
  cout << "Inserting 10 to class 0...\n";
klao@347
    50
  test.insert(10,0);
klao@347
    51
  print(test);
klao@347
    52
klao@347
    53
  cout << "Testing some map values:\n";
klao@347
    54
  cout << " 12: " << int(test[12]) << endl;
klao@347
    55
klao@347
    56
  cout << "Inserting 11 to class 1...\n";
klao@347
    57
  test.insert(11,1);
klao@347
    58
  print(test);
klao@347
    59
klao@347
    60
  cout << "Testing some map values:\n";
klao@347
    61
  cout << " 12: " << int(test[12]) << endl;
klao@347
    62
  cout << " 22: " << int(test[22]) << endl;
klao@347
    63
  cout << " 10: " << int(test[10]) << endl;
klao@347
    64
  cout << " 11: " << int(test[11]) << endl;
klao@347
    65
  cout << " 42: " << int(test[42]) << endl;
klao@347
    66
klao@347
    67
  cout << "Inserting 21 to class 1...\n";
klao@347
    68
  test.insert(21,1);
klao@347
    69
  print(test);
klao@347
    70
klao@347
    71
  cout << "Inserting 20 to class 1...\n";
klao@347
    72
  test.insert(20,0);
klao@347
    73
  print(test);
klao@347
    74
klao@347
    75
  cout << "Testing some map values:\n";
klao@347
    76
  cout << " 12: " << int(test[12]) << endl;
klao@347
    77
  cout << " 22: " << int(test[22]) << endl;
klao@347
    78
  cout << " 10: " << int(test[10]) << endl;
klao@347
    79
  cout << " 20: " << int(test[20]) << endl;
klao@347
    80
  cout << " 11: " << int(test[11]) << endl;
klao@347
    81
  cout << " 21: " << int(test[21]) << endl;
klao@347
    82
  cout << " 42: " << int(test[42]) << endl;
klao@347
    83
klao@347
    84
  cout << "Setting 20 to class 2...\n";
klao@347
    85
  test.set(20,2);
klao@347
    86
  print(test);
klao@347
    87
  
klao@347
    88
  cout << "Setting 10 to class 1...\n";
klao@347
    89
  test.set(10,1);
klao@347
    90
  print(test);
klao@347
    91
  
klao@347
    92
  cout << "Setting 11 to class 1...\n";
klao@347
    93
  test.set(11,1);
klao@347
    94
  print(test);
klao@347
    95
  
klao@347
    96
  cout << "Setting 12 to class 1...\n";
klao@347
    97
  test.set(12,1);
klao@347
    98
  print(test);
klao@347
    99
  
klao@347
   100
  cout << "Setting 21 to class 2...\n";
klao@347
   101
  test.set(21,2);
klao@347
   102
  print(test);
klao@347
   103
  
klao@347
   104
  cout << "Setting 22 to class 2...\n";
klao@347
   105
  test.set(22,2);
klao@347
   106
  print(test);
klao@347
   107
  
klao@347
   108
  cout << "Testing some map values:\n";
klao@347
   109
  cout << " 12: " << int(test[12]) << endl;
klao@347
   110
  cout << " 22: " << int(test[22]) << endl;
klao@347
   111
  cout << " 10: " << int(test[10]) << endl;
klao@347
   112
  cout << " 20: " << int(test[20]) << endl;
klao@347
   113
  cout << " 11: " << int(test[11]) << endl;
klao@347
   114
  cout << " 21: " << int(test[21]) << endl;
klao@347
   115
  cout << " 42: " << int(test[42]) << endl;
klao@347
   116
klao@347
   117
}