gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Rename ValueIterator to ValueIt in graph maps (#302) but keep ValueIterator as an alias in CrossRefMap (only for reverse compatibility).
0 2 0
default
2 files changed with 42 insertions and 36 deletions:
↑ Collapse diff ↑
Ignore white space 2048 line context
... ...
@@ -886,2861 +886,2868 @@
886 886
  /// Its \c Key and \c Value types are inherited from \c M1.
887 887
  /// The \c Key and \c Value of \c M2 must be convertible to those of
888 888
  /// \c M1.
889 889
  ///
890 890
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
891 891
  /// \code
892 892
  ///   MulMap<M1,M2> mm(m1,m2);
893 893
  /// \endcode
894 894
  /// <tt>mm[x]</tt> will be equal to <tt>m1[x]*m2[x]</tt>.
895 895
  ///
896 896
  /// The simplest way of using this map is through the mulMap()
897 897
  /// function.
898 898
  ///
899 899
  /// \sa AddMap, SubMap, DivMap
900 900
  /// \sa ScaleMap, ScaleWriteMap
901 901
  template<typename M1, typename M2>
902 902
  class MulMap : public MapBase<typename M1::Key, typename M1::Value> {
903 903
    const M1 &_m1;
904 904
    const M2 &_m2;
905 905
  public:
906 906
    ///\e
907 907
    typedef typename M1::Key Key;
908 908
    ///\e
909 909
    typedef typename M1::Value Value;
910 910

	
911 911
    /// Constructor
912 912
    MulMap(const M1 &m1,const M2 &m2) : _m1(m1), _m2(m2) {}
913 913
    ///\e
914 914
    Value operator[](const Key &k) const { return _m1[k]*_m2[k]; }
915 915
  };
916 916

	
917 917
  /// Returns a \c MulMap class
918 918

	
919 919
  /// This function just returns a \c MulMap class.
920 920
  ///
921 921
  /// For example, if \c m1 and \c m2 are both maps with \c double
922 922
  /// values, then <tt>mulMap(m1,m2)[x]</tt> will be equal to
923 923
  /// <tt>m1[x]*m2[x]</tt>.
924 924
  ///
925 925
  /// \relates MulMap
926 926
  template<typename M1, typename M2>
927 927
  inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
928 928
    return MulMap<M1, M2>(m1,m2);
929 929
  }
930 930

	
931 931

	
932 932
  /// Quotient of two maps
933 933

	
934 934
  /// This \ref concepts::ReadMap "read-only map" returns the quotient
935 935
  /// of the values of the two given maps.
936 936
  /// Its \c Key and \c Value types are inherited from \c M1.
937 937
  /// The \c Key and \c Value of \c M2 must be convertible to those of
938 938
  /// \c M1.
939 939
  ///
940 940
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
941 941
  /// \code
942 942
  ///   DivMap<M1,M2> dm(m1,m2);
943 943
  /// \endcode
944 944
  /// <tt>dm[x]</tt> will be equal to <tt>m1[x]/m2[x]</tt>.
945 945
  ///
946 946
  /// The simplest way of using this map is through the divMap()
947 947
  /// function.
948 948
  ///
949 949
  /// \sa AddMap, SubMap, MulMap
950 950
  template<typename M1, typename M2>
951 951
  class DivMap : public MapBase<typename M1::Key, typename M1::Value> {
952 952
    const M1 &_m1;
953 953
    const M2 &_m2;
954 954
  public:
955 955
    ///\e
956 956
    typedef typename M1::Key Key;
957 957
    ///\e
958 958
    typedef typename M1::Value Value;
959 959

	
960 960
    /// Constructor
961 961
    DivMap(const M1 &m1,const M2 &m2) : _m1(m1), _m2(m2) {}
962 962
    ///\e
963 963
    Value operator[](const Key &k) const { return _m1[k]/_m2[k]; }
964 964
  };
965 965

	
966 966
  /// Returns a \c DivMap class
967 967

	
968 968
  /// This function just returns a \c DivMap class.
969 969
  ///
970 970
  /// For example, if \c m1 and \c m2 are both maps with \c double
971 971
  /// values, then <tt>divMap(m1,m2)[x]</tt> will be equal to
972 972
  /// <tt>m1[x]/m2[x]</tt>.
973 973
  ///
974 974
  /// \relates DivMap
975 975
  template<typename M1, typename M2>
976 976
  inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) {
977 977
    return DivMap<M1, M2>(m1,m2);
978 978
  }
979 979

	
980 980

	
981 981
  /// Shifts a map with a constant.
982 982

	
983 983
  /// This \ref concepts::ReadMap "read-only map" returns the sum of
984 984
  /// the given map and a constant value (i.e. it shifts the map with
985 985
  /// the constant). Its \c Key and \c Value are inherited from \c M.
986 986
  ///
987 987
  /// Actually,
988 988
  /// \code
989 989
  ///   ShiftMap<M> sh(m,v);
990 990
  /// \endcode
991 991
  /// is equivalent to
992 992
  /// \code
993 993
  ///   ConstMap<M::Key, M::Value> cm(v);
994 994
  ///   AddMap<M, ConstMap<M::Key, M::Value> > sh(m,cm);
995 995
  /// \endcode
996 996
  ///
997 997
  /// The simplest way of using this map is through the shiftMap()
998 998
  /// function.
999 999
  ///
1000 1000
  /// \sa ShiftWriteMap
1001 1001
  template<typename M, typename C = typename M::Value>
1002 1002
  class ShiftMap : public MapBase<typename M::Key, typename M::Value> {
1003 1003
    const M &_m;
1004 1004
    C _v;
1005 1005
  public:
1006 1006
    ///\e
1007 1007
    typedef typename M::Key Key;
1008 1008
    ///\e
1009 1009
    typedef typename M::Value Value;
1010 1010

	
1011 1011
    /// Constructor
1012 1012

	
1013 1013
    /// Constructor.
1014 1014
    /// \param m The undelying map.
1015 1015
    /// \param v The constant value.
1016 1016
    ShiftMap(const M &m, const C &v) : _m(m), _v(v) {}
1017 1017
    ///\e
1018 1018
    Value operator[](const Key &k) const { return _m[k]+_v; }
1019 1019
  };
1020 1020

	
1021 1021
  /// Shifts a map with a constant (read-write version).
1022 1022

	
1023 1023
  /// This \ref concepts::ReadWriteMap "read-write map" returns the sum
1024 1024
  /// of the given map and a constant value (i.e. it shifts the map with
1025 1025
  /// the constant). Its \c Key and \c Value are inherited from \c M.
1026 1026
  /// It makes also possible to write the map.
1027 1027
  ///
1028 1028
  /// The simplest way of using this map is through the shiftWriteMap()
1029 1029
  /// function.
1030 1030
  ///
1031 1031
  /// \sa ShiftMap
1032 1032
  template<typename M, typename C = typename M::Value>
1033 1033
  class ShiftWriteMap : public MapBase<typename M::Key, typename M::Value> {
1034 1034
    M &_m;
1035 1035
    C _v;
1036 1036
  public:
1037 1037
    ///\e
1038 1038
    typedef typename M::Key Key;
1039 1039
    ///\e
1040 1040
    typedef typename M::Value Value;
1041 1041

	
1042 1042
    /// Constructor
1043 1043

	
1044 1044
    /// Constructor.
1045 1045
    /// \param m The undelying map.
1046 1046
    /// \param v The constant value.
1047 1047
    ShiftWriteMap(M &m, const C &v) : _m(m), _v(v) {}
1048 1048
    ///\e
1049 1049
    Value operator[](const Key &k) const { return _m[k]+_v; }
1050 1050
    ///\e
1051 1051
    void set(const Key &k, const Value &v) { _m.set(k, v-_v); }
1052 1052
  };
1053 1053

	
1054 1054
  /// Returns a \c ShiftMap class
1055 1055

	
1056 1056
  /// This function just returns a \c ShiftMap class.
1057 1057
  ///
1058 1058
  /// For example, if \c m is a map with \c double values and \c v is
1059 1059
  /// \c double, then <tt>shiftMap(m,v)[x]</tt> will be equal to
1060 1060
  /// <tt>m[x]+v</tt>.
1061 1061
  ///
1062 1062
  /// \relates ShiftMap
1063 1063
  template<typename M, typename C>
1064 1064
  inline ShiftMap<M, C> shiftMap(const M &m, const C &v) {
1065 1065
    return ShiftMap<M, C>(m,v);
1066 1066
  }
1067 1067

	
1068 1068
  /// Returns a \c ShiftWriteMap class
1069 1069

	
1070 1070
  /// This function just returns a \c ShiftWriteMap class.
1071 1071
  ///
1072 1072
  /// For example, if \c m is a map with \c double values and \c v is
1073 1073
  /// \c double, then <tt>shiftWriteMap(m,v)[x]</tt> will be equal to
1074 1074
  /// <tt>m[x]+v</tt>.
1075 1075
  /// Moreover it makes also possible to write the map.
1076 1076
  ///
1077 1077
  /// \relates ShiftWriteMap
1078 1078
  template<typename M, typename C>
1079 1079
  inline ShiftWriteMap<M, C> shiftWriteMap(M &m, const C &v) {
1080 1080
    return ShiftWriteMap<M, C>(m,v);
1081 1081
  }
1082 1082

	
1083 1083

	
1084 1084
  /// Scales a map with a constant.
1085 1085

	
1086 1086
  /// This \ref concepts::ReadMap "read-only map" returns the value of
1087 1087
  /// the given map multiplied from the left side with a constant value.
1088 1088
  /// Its \c Key and \c Value are inherited from \c M.
1089 1089
  ///
1090 1090
  /// Actually,
1091 1091
  /// \code
1092 1092
  ///   ScaleMap<M> sc(m,v);
1093 1093
  /// \endcode
1094 1094
  /// is equivalent to
1095 1095
  /// \code
1096 1096
  ///   ConstMap<M::Key, M::Value> cm(v);
1097 1097
  ///   MulMap<ConstMap<M::Key, M::Value>, M> sc(cm,m);
1098 1098
  /// \endcode
1099 1099
  ///
1100 1100
  /// The simplest way of using this map is through the scaleMap()
1101 1101
  /// function.
1102 1102
  ///
1103 1103
  /// \sa ScaleWriteMap
1104 1104
  template<typename M, typename C = typename M::Value>
1105 1105
  class ScaleMap : public MapBase<typename M::Key, typename M::Value> {
1106 1106
    const M &_m;
1107 1107
    C _v;
1108 1108
  public:
1109 1109
    ///\e
1110 1110
    typedef typename M::Key Key;
1111 1111
    ///\e
1112 1112
    typedef typename M::Value Value;
1113 1113

	
1114 1114
    /// Constructor
1115 1115

	
1116 1116
    /// Constructor.
1117 1117
    /// \param m The undelying map.
1118 1118
    /// \param v The constant value.
1119 1119
    ScaleMap(const M &m, const C &v) : _m(m), _v(v) {}
1120 1120
    ///\e
1121 1121
    Value operator[](const Key &k) const { return _v*_m[k]; }
1122 1122
  };
1123 1123

	
1124 1124
  /// Scales a map with a constant (read-write version).
1125 1125

	
1126 1126
  /// This \ref concepts::ReadWriteMap "read-write map" returns the value of
1127 1127
  /// the given map multiplied from the left side with a constant value.
1128 1128
  /// Its \c Key and \c Value are inherited from \c M.
1129 1129
  /// It can also be used as write map if the \c / operator is defined
1130 1130
  /// between \c Value and \c C and the given multiplier is not zero.
1131 1131
  ///
1132 1132
  /// The simplest way of using this map is through the scaleWriteMap()
1133 1133
  /// function.
1134 1134
  ///
1135 1135
  /// \sa ScaleMap
1136 1136
  template<typename M, typename C = typename M::Value>
1137 1137
  class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> {
1138 1138
    M &_m;
1139 1139
    C _v;
1140 1140
  public:
1141 1141
    ///\e
1142 1142
    typedef typename M::Key Key;
1143 1143
    ///\e
1144 1144
    typedef typename M::Value Value;
1145 1145

	
1146 1146
    /// Constructor
1147 1147

	
1148 1148
    /// Constructor.
1149 1149
    /// \param m The undelying map.
1150 1150
    /// \param v The constant value.
1151 1151
    ScaleWriteMap(M &m, const C &v) : _m(m), _v(v) {}
1152 1152
    ///\e
1153 1153
    Value operator[](const Key &k) const { return _v*_m[k]; }
1154 1154
    ///\e
1155 1155
    void set(const Key &k, const Value &v) { _m.set(k, v/_v); }
1156 1156
  };
1157 1157

	
1158 1158
  /// Returns a \c ScaleMap class
1159 1159

	
1160 1160
  /// This function just returns a \c ScaleMap class.
1161 1161
  ///
1162 1162
  /// For example, if \c m is a map with \c double values and \c v is
1163 1163
  /// \c double, then <tt>scaleMap(m,v)[x]</tt> will be equal to
1164 1164
  /// <tt>v*m[x]</tt>.
1165 1165
  ///
1166 1166
  /// \relates ScaleMap
1167 1167
  template<typename M, typename C>
1168 1168
  inline ScaleMap<M, C> scaleMap(const M &m, const C &v) {
1169 1169
    return ScaleMap<M, C>(m,v);
1170 1170
  }
1171 1171

	
1172 1172
  /// Returns a \c ScaleWriteMap class
1173 1173

	
1174 1174
  /// This function just returns a \c ScaleWriteMap class.
1175 1175
  ///
1176 1176
  /// For example, if \c m is a map with \c double values and \c v is
1177 1177
  /// \c double, then <tt>scaleWriteMap(m,v)[x]</tt> will be equal to
1178 1178
  /// <tt>v*m[x]</tt>.
1179 1179
  /// Moreover it makes also possible to write the map.
1180 1180
  ///
1181 1181
  /// \relates ScaleWriteMap
1182 1182
  template<typename M, typename C>
1183 1183
  inline ScaleWriteMap<M, C> scaleWriteMap(M &m, const C &v) {
1184 1184
    return ScaleWriteMap<M, C>(m,v);
1185 1185
  }
1186 1186

	
1187 1187

	
1188 1188
  /// Negative of a map
1189 1189

	
1190 1190
  /// This \ref concepts::ReadMap "read-only map" returns the negative
1191 1191
  /// of the values of the given map (using the unary \c - operator).
1192 1192
  /// Its \c Key and \c Value are inherited from \c M.
1193 1193
  ///
1194 1194
  /// If M::Value is \c int, \c double etc., then
1195 1195
  /// \code
1196 1196
  ///   NegMap<M> neg(m);
1197 1197
  /// \endcode
1198 1198
  /// is equivalent to
1199 1199
  /// \code
1200 1200
  ///   ScaleMap<M> neg(m,-1);
1201 1201
  /// \endcode
1202 1202
  ///
1203 1203
  /// The simplest way of using this map is through the negMap()
1204 1204
  /// function.
1205 1205
  ///
1206 1206
  /// \sa NegWriteMap
1207 1207
  template<typename M>
1208 1208
  class NegMap : public MapBase<typename M::Key, typename M::Value> {
1209 1209
    const M& _m;
1210 1210
  public:
1211 1211
    ///\e
1212 1212
    typedef typename M::Key Key;
1213 1213
    ///\e
1214 1214
    typedef typename M::Value Value;
1215 1215

	
1216 1216
    /// Constructor
1217 1217
    NegMap(const M &m) : _m(m) {}
1218 1218
    ///\e
1219 1219
    Value operator[](const Key &k) const { return -_m[k]; }
1220 1220
  };
1221 1221

	
1222 1222
  /// Negative of a map (read-write version)
1223 1223

	
1224 1224
  /// This \ref concepts::ReadWriteMap "read-write map" returns the
1225 1225
  /// negative of the values of the given map (using the unary \c -
1226 1226
  /// operator).
1227 1227
  /// Its \c Key and \c Value are inherited from \c M.
1228 1228
  /// It makes also possible to write the map.
1229 1229
  ///
1230 1230
  /// If M::Value is \c int, \c double etc., then
1231 1231
  /// \code
1232 1232
  ///   NegWriteMap<M> neg(m);
1233 1233
  /// \endcode
1234 1234
  /// is equivalent to
1235 1235
  /// \code
1236 1236
  ///   ScaleWriteMap<M> neg(m,-1);
1237 1237
  /// \endcode
1238 1238
  ///
1239 1239
  /// The simplest way of using this map is through the negWriteMap()
1240 1240
  /// function.
1241 1241
  ///
1242 1242
  /// \sa NegMap
1243 1243
  template<typename M>
1244 1244
  class NegWriteMap : public MapBase<typename M::Key, typename M::Value> {
1245 1245
    M &_m;
1246 1246
  public:
1247 1247
    ///\e
1248 1248
    typedef typename M::Key Key;
1249 1249
    ///\e
1250 1250
    typedef typename M::Value Value;
1251 1251

	
1252 1252
    /// Constructor
1253 1253
    NegWriteMap(M &m) : _m(m) {}
1254 1254
    ///\e
1255 1255
    Value operator[](const Key &k) const { return -_m[k]; }
1256 1256
    ///\e
1257 1257
    void set(const Key &k, const Value &v) { _m.set(k, -v); }
1258 1258
  };
1259 1259

	
1260 1260
  /// Returns a \c NegMap class
1261 1261

	
1262 1262
  /// This function just returns a \c NegMap class.
1263 1263
  ///
1264 1264
  /// For example, if \c m is a map with \c double values, then
1265 1265
  /// <tt>negMap(m)[x]</tt> will be equal to <tt>-m[x]</tt>.
1266 1266
  ///
1267 1267
  /// \relates NegMap
1268 1268
  template <typename M>
1269 1269
  inline NegMap<M> negMap(const M &m) {
1270 1270
    return NegMap<M>(m);
1271 1271
  }
1272 1272

	
1273 1273
  /// Returns a \c NegWriteMap class
1274 1274

	
1275 1275
  /// This function just returns a \c NegWriteMap class.
1276 1276
  ///
1277 1277
  /// For example, if \c m is a map with \c double values, then
1278 1278
  /// <tt>negWriteMap(m)[x]</tt> will be equal to <tt>-m[x]</tt>.
1279 1279
  /// Moreover it makes also possible to write the map.
1280 1280
  ///
1281 1281
  /// \relates NegWriteMap
1282 1282
  template <typename M>
1283 1283
  inline NegWriteMap<M> negWriteMap(M &m) {
1284 1284
    return NegWriteMap<M>(m);
1285 1285
  }
1286 1286

	
1287 1287

	
1288 1288
  /// Absolute value of a map
1289 1289

	
1290 1290
  /// This \ref concepts::ReadMap "read-only map" returns the absolute
1291 1291
  /// value of the values of the given map.
1292 1292
  /// Its \c Key and \c Value are inherited from \c M.
1293 1293
  /// \c Value must be comparable to \c 0 and the unary \c -
1294 1294
  /// operator must be defined for it, of course.
1295 1295
  ///
1296 1296
  /// The simplest way of using this map is through the absMap()
1297 1297
  /// function.
1298 1298
  template<typename M>
1299 1299
  class AbsMap : public MapBase<typename M::Key, typename M::Value> {
1300 1300
    const M &_m;
1301 1301
  public:
1302 1302
    ///\e
1303 1303
    typedef typename M::Key Key;
1304 1304
    ///\e
1305 1305
    typedef typename M::Value Value;
1306 1306

	
1307 1307
    /// Constructor
1308 1308
    AbsMap(const M &m) : _m(m) {}
1309 1309
    ///\e
1310 1310
    Value operator[](const Key &k) const {
1311 1311
      Value tmp = _m[k];
1312 1312
      return tmp >= 0 ? tmp : -tmp;
1313 1313
    }
1314 1314

	
1315 1315
  };
1316 1316

	
1317 1317
  /// Returns an \c AbsMap class
1318 1318

	
1319 1319
  /// This function just returns an \c AbsMap class.
1320 1320
  ///
1321 1321
  /// For example, if \c m is a map with \c double values, then
1322 1322
  /// <tt>absMap(m)[x]</tt> will be equal to <tt>m[x]</tt> if
1323 1323
  /// it is positive or zero and <tt>-m[x]</tt> if <tt>m[x]</tt> is
1324 1324
  /// negative.
1325 1325
  ///
1326 1326
  /// \relates AbsMap
1327 1327
  template<typename M>
1328 1328
  inline AbsMap<M> absMap(const M &m) {
1329 1329
    return AbsMap<M>(m);
1330 1330
  }
1331 1331

	
1332 1332
  /// @}
1333 1333

	
1334 1334
  // Logical maps and map adaptors:
1335 1335

	
1336 1336
  /// \addtogroup maps
1337 1337
  /// @{
1338 1338

	
1339 1339
  /// Constant \c true map.
1340 1340

	
1341 1341
  /// This \ref concepts::ReadMap "read-only map" assigns \c true to
1342 1342
  /// each key.
1343 1343
  ///
1344 1344
  /// Note that
1345 1345
  /// \code
1346 1346
  ///   TrueMap<K> tm;
1347 1347
  /// \endcode
1348 1348
  /// is equivalent to
1349 1349
  /// \code
1350 1350
  ///   ConstMap<K,bool> tm(true);
1351 1351
  /// \endcode
1352 1352
  ///
1353 1353
  /// \sa FalseMap
1354 1354
  /// \sa ConstMap
1355 1355
  template <typename K>
1356 1356
  class TrueMap : public MapBase<K, bool> {
1357 1357
  public:
1358 1358
    ///\e
1359 1359
    typedef K Key;
1360 1360
    ///\e
1361 1361
    typedef bool Value;
1362 1362

	
1363 1363
    /// Gives back \c true.
1364 1364
    Value operator[](const Key&) const { return true; }
1365 1365
  };
1366 1366

	
1367 1367
  /// Returns a \c TrueMap class
1368 1368

	
1369 1369
  /// This function just returns a \c TrueMap class.
1370 1370
  /// \relates TrueMap
1371 1371
  template<typename K>
1372 1372
  inline TrueMap<K> trueMap() {
1373 1373
    return TrueMap<K>();
1374 1374
  }
1375 1375

	
1376 1376

	
1377 1377
  /// Constant \c false map.
1378 1378

	
1379 1379
  /// This \ref concepts::ReadMap "read-only map" assigns \c false to
1380 1380
  /// each key.
1381 1381
  ///
1382 1382
  /// Note that
1383 1383
  /// \code
1384 1384
  ///   FalseMap<K> fm;
1385 1385
  /// \endcode
1386 1386
  /// is equivalent to
1387 1387
  /// \code
1388 1388
  ///   ConstMap<K,bool> fm(false);
1389 1389
  /// \endcode
1390 1390
  ///
1391 1391
  /// \sa TrueMap
1392 1392
  /// \sa ConstMap
1393 1393
  template <typename K>
1394 1394
  class FalseMap : public MapBase<K, bool> {
1395 1395
  public:
1396 1396
    ///\e
1397 1397
    typedef K Key;
1398 1398
    ///\e
1399 1399
    typedef bool Value;
1400 1400

	
1401 1401
    /// Gives back \c false.
1402 1402
    Value operator[](const Key&) const { return false; }
1403 1403
  };
1404 1404

	
1405 1405
  /// Returns a \c FalseMap class
1406 1406

	
1407 1407
  /// This function just returns a \c FalseMap class.
1408 1408
  /// \relates FalseMap
1409 1409
  template<typename K>
1410 1410
  inline FalseMap<K> falseMap() {
1411 1411
    return FalseMap<K>();
1412 1412
  }
1413 1413

	
1414 1414
  /// @}
1415 1415

	
1416 1416
  /// \addtogroup map_adaptors
1417 1417
  /// @{
1418 1418

	
1419 1419
  /// Logical 'and' of two maps
1420 1420

	
1421 1421
  /// This \ref concepts::ReadMap "read-only map" returns the logical
1422 1422
  /// 'and' of the values of the two given maps.
1423 1423
  /// Its \c Key type is inherited from \c M1 and its \c Value type is
1424 1424
  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
1425 1425
  ///
1426 1426
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
1427 1427
  /// \code
1428 1428
  ///   AndMap<M1,M2> am(m1,m2);
1429 1429
  /// \endcode
1430 1430
  /// <tt>am[x]</tt> will be equal to <tt>m1[x]&&m2[x]</tt>.
1431 1431
  ///
1432 1432
  /// The simplest way of using this map is through the andMap()
1433 1433
  /// function.
1434 1434
  ///
1435 1435
  /// \sa OrMap
1436 1436
  /// \sa NotMap, NotWriteMap
1437 1437
  template<typename M1, typename M2>
1438 1438
  class AndMap : public MapBase<typename M1::Key, bool> {
1439 1439
    const M1 &_m1;
1440 1440
    const M2 &_m2;
1441 1441
  public:
1442 1442
    ///\e
1443 1443
    typedef typename M1::Key Key;
1444 1444
    ///\e
1445 1445
    typedef bool Value;
1446 1446

	
1447 1447
    /// Constructor
1448 1448
    AndMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1449 1449
    ///\e
1450 1450
    Value operator[](const Key &k) const { return _m1[k]&&_m2[k]; }
1451 1451
  };
1452 1452

	
1453 1453
  /// Returns an \c AndMap class
1454 1454

	
1455 1455
  /// This function just returns an \c AndMap class.
1456 1456
  ///
1457 1457
  /// For example, if \c m1 and \c m2 are both maps with \c bool values,
1458 1458
  /// then <tt>andMap(m1,m2)[x]</tt> will be equal to
1459 1459
  /// <tt>m1[x]&&m2[x]</tt>.
1460 1460
  ///
1461 1461
  /// \relates AndMap
1462 1462
  template<typename M1, typename M2>
1463 1463
  inline AndMap<M1, M2> andMap(const M1 &m1, const M2 &m2) {
1464 1464
    return AndMap<M1, M2>(m1,m2);
1465 1465
  }
1466 1466

	
1467 1467

	
1468 1468
  /// Logical 'or' of two maps
1469 1469

	
1470 1470
  /// This \ref concepts::ReadMap "read-only map" returns the logical
1471 1471
  /// 'or' of the values of the two given maps.
1472 1472
  /// Its \c Key type is inherited from \c M1 and its \c Value type is
1473 1473
  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
1474 1474
  ///
1475 1475
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
1476 1476
  /// \code
1477 1477
  ///   OrMap<M1,M2> om(m1,m2);
1478 1478
  /// \endcode
1479 1479
  /// <tt>om[x]</tt> will be equal to <tt>m1[x]||m2[x]</tt>.
1480 1480
  ///
1481 1481
  /// The simplest way of using this map is through the orMap()
1482 1482
  /// function.
1483 1483
  ///
1484 1484
  /// \sa AndMap
1485 1485
  /// \sa NotMap, NotWriteMap
1486 1486
  template<typename M1, typename M2>
1487 1487
  class OrMap : public MapBase<typename M1::Key, bool> {
1488 1488
    const M1 &_m1;
1489 1489
    const M2 &_m2;
1490 1490
  public:
1491 1491
    ///\e
1492 1492
    typedef typename M1::Key Key;
1493 1493
    ///\e
1494 1494
    typedef bool Value;
1495 1495

	
1496 1496
    /// Constructor
1497 1497
    OrMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1498 1498
    ///\e
1499 1499
    Value operator[](const Key &k) const { return _m1[k]||_m2[k]; }
1500 1500
  };
1501 1501

	
1502 1502
  /// Returns an \c OrMap class
1503 1503

	
1504 1504
  /// This function just returns an \c OrMap class.
1505 1505
  ///
1506 1506
  /// For example, if \c m1 and \c m2 are both maps with \c bool values,
1507 1507
  /// then <tt>orMap(m1,m2)[x]</tt> will be equal to
1508 1508
  /// <tt>m1[x]||m2[x]</tt>.
1509 1509
  ///
1510 1510
  /// \relates OrMap
1511 1511
  template<typename M1, typename M2>
1512 1512
  inline OrMap<M1, M2> orMap(const M1 &m1, const M2 &m2) {
1513 1513
    return OrMap<M1, M2>(m1,m2);
1514 1514
  }
1515 1515

	
1516 1516

	
1517 1517
  /// Logical 'not' of a map
1518 1518

	
1519 1519
  /// This \ref concepts::ReadMap "read-only map" returns the logical
1520 1520
  /// negation of the values of the given map.
1521 1521
  /// Its \c Key is inherited from \c M and its \c Value is \c bool.
1522 1522
  ///
1523 1523
  /// The simplest way of using this map is through the notMap()
1524 1524
  /// function.
1525 1525
  ///
1526 1526
  /// \sa NotWriteMap
1527 1527
  template <typename M>
1528 1528
  class NotMap : public MapBase<typename M::Key, bool> {
1529 1529
    const M &_m;
1530 1530
  public:
1531 1531
    ///\e
1532 1532
    typedef typename M::Key Key;
1533 1533
    ///\e
1534 1534
    typedef bool Value;
1535 1535

	
1536 1536
    /// Constructor
1537 1537
    NotMap(const M &m) : _m(m) {}
1538 1538
    ///\e
1539 1539
    Value operator[](const Key &k) const { return !_m[k]; }
1540 1540
  };
1541 1541

	
1542 1542
  /// Logical 'not' of a map (read-write version)
1543 1543

	
1544 1544
  /// This \ref concepts::ReadWriteMap "read-write map" returns the
1545 1545
  /// logical negation of the values of the given map.
1546 1546
  /// Its \c Key is inherited from \c M and its \c Value is \c bool.
1547 1547
  /// It makes also possible to write the map. When a value is set,
1548 1548
  /// the opposite value is set to the original map.
1549 1549
  ///
1550 1550
  /// The simplest way of using this map is through the notWriteMap()
1551 1551
  /// function.
1552 1552
  ///
1553 1553
  /// \sa NotMap
1554 1554
  template <typename M>
1555 1555
  class NotWriteMap : public MapBase<typename M::Key, bool> {
1556 1556
    M &_m;
1557 1557
  public:
1558 1558
    ///\e
1559 1559
    typedef typename M::Key Key;
1560 1560
    ///\e
1561 1561
    typedef bool Value;
1562 1562

	
1563 1563
    /// Constructor
1564 1564
    NotWriteMap(M &m) : _m(m) {}
1565 1565
    ///\e
1566 1566
    Value operator[](const Key &k) const { return !_m[k]; }
1567 1567
    ///\e
1568 1568
    void set(const Key &k, bool v) { _m.set(k, !v); }
1569 1569
  };
1570 1570

	
1571 1571
  /// Returns a \c NotMap class
1572 1572

	
1573 1573
  /// This function just returns a \c NotMap class.
1574 1574
  ///
1575 1575
  /// For example, if \c m is a map with \c bool values, then
1576 1576
  /// <tt>notMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>.
1577 1577
  ///
1578 1578
  /// \relates NotMap
1579 1579
  template <typename M>
1580 1580
  inline NotMap<M> notMap(const M &m) {
1581 1581
    return NotMap<M>(m);
1582 1582
  }
1583 1583

	
1584 1584
  /// Returns a \c NotWriteMap class
1585 1585

	
1586 1586
  /// This function just returns a \c NotWriteMap class.
1587 1587
  ///
1588 1588
  /// For example, if \c m is a map with \c bool values, then
1589 1589
  /// <tt>notWriteMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>.
1590 1590
  /// Moreover it makes also possible to write the map.
1591 1591
  ///
1592 1592
  /// \relates NotWriteMap
1593 1593
  template <typename M>
1594 1594
  inline NotWriteMap<M> notWriteMap(M &m) {
1595 1595
    return NotWriteMap<M>(m);
1596 1596
  }
1597 1597

	
1598 1598

	
1599 1599
  /// Combination of two maps using the \c == operator
1600 1600

	
1601 1601
  /// This \ref concepts::ReadMap "read-only map" assigns \c true to
1602 1602
  /// the keys for which the corresponding values of the two maps are
1603 1603
  /// equal.
1604 1604
  /// Its \c Key type is inherited from \c M1 and its \c Value type is
1605 1605
  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
1606 1606
  ///
1607 1607
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
1608 1608
  /// \code
1609 1609
  ///   EqualMap<M1,M2> em(m1,m2);
1610 1610
  /// \endcode
1611 1611
  /// <tt>em[x]</tt> will be equal to <tt>m1[x]==m2[x]</tt>.
1612 1612
  ///
1613 1613
  /// The simplest way of using this map is through the equalMap()
1614 1614
  /// function.
1615 1615
  ///
1616 1616
  /// \sa LessMap
1617 1617
  template<typename M1, typename M2>
1618 1618
  class EqualMap : public MapBase<typename M1::Key, bool> {
1619 1619
    const M1 &_m1;
1620 1620
    const M2 &_m2;
1621 1621
  public:
1622 1622
    ///\e
1623 1623
    typedef typename M1::Key Key;
1624 1624
    ///\e
1625 1625
    typedef bool Value;
1626 1626

	
1627 1627
    /// Constructor
1628 1628
    EqualMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1629 1629
    ///\e
1630 1630
    Value operator[](const Key &k) const { return _m1[k]==_m2[k]; }
1631 1631
  };
1632 1632

	
1633 1633
  /// Returns an \c EqualMap class
1634 1634

	
1635 1635
  /// This function just returns an \c EqualMap class.
1636 1636
  ///
1637 1637
  /// For example, if \c m1 and \c m2 are maps with keys and values of
1638 1638
  /// the same type, then <tt>equalMap(m1,m2)[x]</tt> will be equal to
1639 1639
  /// <tt>m1[x]==m2[x]</tt>.
1640 1640
  ///
1641 1641
  /// \relates EqualMap
1642 1642
  template<typename M1, typename M2>
1643 1643
  inline EqualMap<M1, M2> equalMap(const M1 &m1, const M2 &m2) {
1644 1644
    return EqualMap<M1, M2>(m1,m2);
1645 1645
  }
1646 1646

	
1647 1647

	
1648 1648
  /// Combination of two maps using the \c < operator
1649 1649

	
1650 1650
  /// This \ref concepts::ReadMap "read-only map" assigns \c true to
1651 1651
  /// the keys for which the corresponding value of the first map is
1652 1652
  /// less then the value of the second map.
1653 1653
  /// Its \c Key type is inherited from \c M1 and its \c Value type is
1654 1654
  /// \c bool. \c M2::Key must be convertible to \c M1::Key.
1655 1655
  ///
1656 1656
  /// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for
1657 1657
  /// \code
1658 1658
  ///   LessMap<M1,M2> lm(m1,m2);
1659 1659
  /// \endcode
1660 1660
  /// <tt>lm[x]</tt> will be equal to <tt>m1[x]<m2[x]</tt>.
1661 1661
  ///
1662 1662
  /// The simplest way of using this map is through the lessMap()
1663 1663
  /// function.
1664 1664
  ///
1665 1665
  /// \sa EqualMap
1666 1666
  template<typename M1, typename M2>
1667 1667
  class LessMap : public MapBase<typename M1::Key, bool> {
1668 1668
    const M1 &_m1;
1669 1669
    const M2 &_m2;
1670 1670
  public:
1671 1671
    ///\e
1672 1672
    typedef typename M1::Key Key;
1673 1673
    ///\e
1674 1674
    typedef bool Value;
1675 1675

	
1676 1676
    /// Constructor
1677 1677
    LessMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
1678 1678
    ///\e
1679 1679
    Value operator[](const Key &k) const { return _m1[k]<_m2[k]; }
1680 1680
  };
1681 1681

	
1682 1682
  /// Returns an \c LessMap class
1683 1683

	
1684 1684
  /// This function just returns an \c LessMap class.
1685 1685
  ///
1686 1686
  /// For example, if \c m1 and \c m2 are maps with keys and values of
1687 1687
  /// the same type, then <tt>lessMap(m1,m2)[x]</tt> will be equal to
1688 1688
  /// <tt>m1[x]<m2[x]</tt>.
1689 1689
  ///
1690 1690
  /// \relates LessMap
1691 1691
  template<typename M1, typename M2>
1692 1692
  inline LessMap<M1, M2> lessMap(const M1 &m1, const M2 &m2) {
1693 1693
    return LessMap<M1, M2>(m1,m2);
1694 1694
  }
1695 1695

	
1696 1696
  namespace _maps_bits {
1697 1697

	
1698 1698
    template <typename _Iterator, typename Enable = void>
1699 1699
    struct IteratorTraits {
1700 1700
      typedef typename std::iterator_traits<_Iterator>::value_type Value;
1701 1701
    };
1702 1702

	
1703 1703
    template <typename _Iterator>
1704 1704
    struct IteratorTraits<_Iterator,
1705 1705
      typename exists<typename _Iterator::container_type>::type>
1706 1706
    {
1707 1707
      typedef typename _Iterator::container_type::value_type Value;
1708 1708
    };
1709 1709

	
1710 1710
  }
1711 1711

	
1712 1712
  /// @}
1713 1713

	
1714 1714
  /// \addtogroup maps
1715 1715
  /// @{
1716 1716

	
1717 1717
  /// \brief Writable bool map for logging each \c true assigned element
1718 1718
  ///
1719 1719
  /// A \ref concepts::WriteMap "writable" bool map for logging
1720 1720
  /// each \c true assigned element, i.e it copies subsequently each
1721 1721
  /// keys set to \c true to the given iterator.
1722 1722
  /// The most important usage of it is storing certain nodes or arcs
1723 1723
  /// that were marked \c true by an algorithm.
1724 1724
  ///
1725 1725
  /// There are several algorithms that provide solutions through bool
1726 1726
  /// maps and most of them assign \c true at most once for each key.
1727 1727
  /// In these cases it is a natural request to store each \c true
1728 1728
  /// assigned elements (in order of the assignment), which can be
1729 1729
  /// easily done with LoggerBoolMap.
1730 1730
  ///
1731 1731
  /// The simplest way of using this map is through the loggerBoolMap()
1732 1732
  /// function.
1733 1733
  ///
1734 1734
  /// \tparam IT The type of the iterator.
1735 1735
  /// \tparam KEY The key type of the map. The default value set
1736 1736
  /// according to the iterator type should work in most cases.
1737 1737
  ///
1738 1738
  /// \note The container of the iterator must contain enough space
1739 1739
  /// for the elements or the iterator should be an inserter iterator.
1740 1740
#ifdef DOXYGEN
1741 1741
  template <typename IT, typename KEY>
1742 1742
#else
1743 1743
  template <typename IT,
1744 1744
            typename KEY = typename _maps_bits::IteratorTraits<IT>::Value>
1745 1745
#endif
1746 1746
  class LoggerBoolMap : public MapBase<KEY, bool> {
1747 1747
  public:
1748 1748

	
1749 1749
    ///\e
1750 1750
    typedef KEY Key;
1751 1751
    ///\e
1752 1752
    typedef bool Value;
1753 1753
    ///\e
1754 1754
    typedef IT Iterator;
1755 1755

	
1756 1756
    /// Constructor
1757 1757
    LoggerBoolMap(Iterator it)
1758 1758
      : _begin(it), _end(it) {}
1759 1759

	
1760 1760
    /// Gives back the given iterator set for the first key
1761 1761
    Iterator begin() const {
1762 1762
      return _begin;
1763 1763
    }
1764 1764

	
1765 1765
    /// Gives back the the 'after the last' iterator
1766 1766
    Iterator end() const {
1767 1767
      return _end;
1768 1768
    }
1769 1769

	
1770 1770
    /// The set function of the map
1771 1771
    void set(const Key& key, Value value) {
1772 1772
      if (value) {
1773 1773
        *_end++ = key;
1774 1774
      }
1775 1775
    }
1776 1776

	
1777 1777
  private:
1778 1778
    Iterator _begin;
1779 1779
    Iterator _end;
1780 1780
  };
1781 1781

	
1782 1782
  /// Returns a \c LoggerBoolMap class
1783 1783

	
1784 1784
  /// This function just returns a \c LoggerBoolMap class.
1785 1785
  ///
1786 1786
  /// The most important usage of it is storing certain nodes or arcs
1787 1787
  /// that were marked \c true by an algorithm.
1788 1788
  /// For example it makes easier to store the nodes in the processing
1789 1789
  /// order of Dfs algorithm, as the following examples show.
1790 1790
  /// \code
1791 1791
  ///   std::vector<Node> v;
1792 1792
  ///   dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run();
1793 1793
  /// \endcode
1794 1794
  /// \code
1795 1795
  ///   std::vector<Node> v(countNodes(g));
1796 1796
  ///   dfs(g,s).processedMap(loggerBoolMap(v.begin())).run();
1797 1797
  /// \endcode
1798 1798
  ///
1799 1799
  /// \note The container of the iterator must contain enough space
1800 1800
  /// for the elements or the iterator should be an inserter iterator.
1801 1801
  ///
1802 1802
  /// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so
1803 1803
  /// it cannot be used when a readable map is needed, for example as
1804 1804
  /// \c ReachedMap for \c Bfs, \c Dfs and \c Dijkstra algorithms.
1805 1805
  ///
1806 1806
  /// \relates LoggerBoolMap
1807 1807
  template<typename Iterator>
1808 1808
  inline LoggerBoolMap<Iterator> loggerBoolMap(Iterator it) {
1809 1809
    return LoggerBoolMap<Iterator>(it);
1810 1810
  }
1811 1811

	
1812 1812
  /// @}
1813 1813

	
1814 1814
  /// \addtogroup graph_maps
1815 1815
  /// @{
1816 1816

	
1817 1817
  /// \brief Provides an immutable and unique id for each item in a graph.
1818 1818
  ///
1819 1819
  /// IdMap provides a unique and immutable id for each item of the
1820 1820
  /// same type (\c Node, \c Arc or \c Edge) in a graph. This id is
1821 1821
  ///  - \b unique: different items get different ids,
1822 1822
  ///  - \b immutable: the id of an item does not change (even if you
1823 1823
  ///    delete other nodes).
1824 1824
  ///
1825 1825
  /// Using this map you get access (i.e. can read) the inner id values of
1826 1826
  /// the items stored in the graph, which is returned by the \c id()
1827 1827
  /// function of the graph. This map can be inverted with its member
1828 1828
  /// class \c InverseMap or with the \c operator()() member.
1829 1829
  ///
1830 1830
  /// \tparam GR The graph type.
1831 1831
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1832 1832
  /// \c GR::Edge).
1833 1833
  ///
1834 1834
  /// \see RangeIdMap
1835 1835
  template <typename GR, typename K>
1836 1836
  class IdMap : public MapBase<K, int> {
1837 1837
  public:
1838 1838
    /// The graph type of IdMap.
1839 1839
    typedef GR Graph;
1840 1840
    typedef GR Digraph;
1841 1841
    /// The key type of IdMap (\c Node, \c Arc or \c Edge).
1842 1842
    typedef K Item;
1843 1843
    /// The key type of IdMap (\c Node, \c Arc or \c Edge).
1844 1844
    typedef K Key;
1845 1845
    /// The value type of IdMap.
1846 1846
    typedef int Value;
1847 1847

	
1848 1848
    /// \brief Constructor.
1849 1849
    ///
1850 1850
    /// Constructor of the map.
1851 1851
    explicit IdMap(const Graph& graph) : _graph(&graph) {}
1852 1852

	
1853 1853
    /// \brief Gives back the \e id of the item.
1854 1854
    ///
1855 1855
    /// Gives back the immutable and unique \e id of the item.
1856 1856
    int operator[](const Item& item) const { return _graph->id(item);}
1857 1857

	
1858 1858
    /// \brief Gives back the \e item by its id.
1859 1859
    ///
1860 1860
    /// Gives back the \e item by its id.
1861 1861
    Item operator()(int id) { return _graph->fromId(id, Item()); }
1862 1862

	
1863 1863
  private:
1864 1864
    const Graph* _graph;
1865 1865

	
1866 1866
  public:
1867 1867

	
1868 1868
    /// \brief The inverse map type of IdMap.
1869 1869
    ///
1870 1870
    /// The inverse map type of IdMap. The subscript operator gives back
1871 1871
    /// an item by its id.
1872 1872
    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
1873 1873
    /// \see inverse()
1874 1874
    class InverseMap {
1875 1875
    public:
1876 1876

	
1877 1877
      /// \brief Constructor.
1878 1878
      ///
1879 1879
      /// Constructor for creating an id-to-item map.
1880 1880
      explicit InverseMap(const Graph& graph) : _graph(&graph) {}
1881 1881

	
1882 1882
      /// \brief Constructor.
1883 1883
      ///
1884 1884
      /// Constructor for creating an id-to-item map.
1885 1885
      explicit InverseMap(const IdMap& map) : _graph(map._graph) {}
1886 1886

	
1887 1887
      /// \brief Gives back an item by its id.
1888 1888
      ///
1889 1889
      /// Gives back an item by its id.
1890 1890
      Item operator[](int id) const { return _graph->fromId(id, Item());}
1891 1891

	
1892 1892
    private:
1893 1893
      const Graph* _graph;
1894 1894
    };
1895 1895

	
1896 1896
    /// \brief Gives back the inverse of the map.
1897 1897
    ///
1898 1898
    /// Gives back the inverse of the IdMap.
1899 1899
    InverseMap inverse() const { return InverseMap(*_graph);}
1900 1900
  };
1901 1901

	
1902 1902

	
1903 1903
  /// \brief General cross reference graph map type.
1904 1904

	
1905 1905
  /// This class provides simple invertable graph maps.
1906 1906
  /// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap)
1907 1907
  /// and if a key is set to a new value, then stores it in the inverse map.
1908 1908
  /// The graph items can be accessed by their values either using
1909 1909
  /// \c InverseMap or \c operator()(), and the values of the map can be
1910
  /// accessed with an STL compatible forward iterator (\c ValueIterator).
1910
  /// accessed with an STL compatible forward iterator (\c ValueIt).
1911 1911
  /// 
1912 1912
  /// This map is intended to be used when all associated values are
1913 1913
  /// different (the map is actually invertable) or there are only a few
1914 1914
  /// items with the same value.
1915 1915
  /// Otherwise consider to use \c IterableValueMap, which is more 
1916 1916
  /// suitable and more efficient for such cases. It provides iterators
1917 1917
  /// to traverse the items with the same associated value, however
1918 1918
  /// it does not have \c InverseMap.
1919 1919
  ///
1920 1920
  /// This type is not reference map, so it cannot be modified with
1921 1921
  /// the subscript operator.
1922 1922
  ///
1923 1923
  /// \tparam GR The graph type.
1924 1924
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
1925 1925
  /// \c GR::Edge).
1926 1926
  /// \tparam V The value type of the map.
1927 1927
  ///
1928 1928
  /// \see IterableValueMap
1929 1929
  template <typename GR, typename K, typename V>
1930 1930
  class CrossRefMap
1931 1931
    : protected ItemSetTraits<GR, K>::template Map<V>::Type {
1932 1932
  private:
1933 1933

	
1934 1934
    typedef typename ItemSetTraits<GR, K>::
1935 1935
      template Map<V>::Type Map;
1936 1936

	
1937 1937
    typedef std::multimap<V, K> Container;
1938 1938
    Container _inv_map;
1939 1939

	
1940 1940
  public:
1941 1941

	
1942 1942
    /// The graph type of CrossRefMap.
1943 1943
    typedef GR Graph;
1944 1944
    typedef GR Digraph;
1945 1945
    /// The key type of CrossRefMap (\c Node, \c Arc or \c Edge).
1946 1946
    typedef K Item;
1947 1947
    /// The key type of CrossRefMap (\c Node, \c Arc or \c Edge).
1948 1948
    typedef K Key;
1949 1949
    /// The value type of CrossRefMap.
1950 1950
    typedef V Value;
1951 1951

	
1952 1952
    /// \brief Constructor.
1953 1953
    ///
1954 1954
    /// Construct a new CrossRefMap for the given graph.
1955 1955
    explicit CrossRefMap(const Graph& graph) : Map(graph) {}
1956 1956

	
1957 1957
    /// \brief Forward iterator for values.
1958 1958
    ///
1959 1959
    /// This iterator is an STL compatible forward
1960 1960
    /// iterator on the values of the map. The values can
1961 1961
    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
1962 1962
    /// They are considered with multiplicity, so each value is
1963 1963
    /// traversed for each item it is assigned to.
1964
    class ValueIterator
1964
    class ValueIt
1965 1965
      : public std::iterator<std::forward_iterator_tag, Value> {
1966 1966
      friend class CrossRefMap;
1967 1967
    private:
1968
      ValueIterator(typename Container::const_iterator _it)
1968
      ValueIt(typename Container::const_iterator _it)
1969 1969
        : it(_it) {}
1970 1970
    public:
1971 1971

	
1972 1972
      /// Constructor
1973
      ValueIterator() {}
1973
      ValueIt() {}
1974 1974

	
1975 1975
      /// \e
1976
      ValueIterator& operator++() { ++it; return *this; }
1976
      ValueIt& operator++() { ++it; return *this; }
1977 1977
      /// \e
1978
      ValueIterator operator++(int) {
1979
        ValueIterator tmp(*this);
1978
      ValueIt operator++(int) {
1979
        ValueIt tmp(*this);
1980 1980
        operator++();
1981 1981
        return tmp;
1982 1982
      }
1983 1983

	
1984 1984
      /// \e
1985 1985
      const Value& operator*() const { return it->first; }
1986 1986
      /// \e
1987 1987
      const Value* operator->() const { return &(it->first); }
1988 1988

	
1989 1989
      /// \e
1990
      bool operator==(ValueIterator jt) const { return it == jt.it; }
1990
      bool operator==(ValueIt jt) const { return it == jt.it; }
1991 1991
      /// \e
1992
      bool operator!=(ValueIterator jt) const { return it != jt.it; }
1992
      bool operator!=(ValueIt jt) const { return it != jt.it; }
1993 1993

	
1994 1994
    private:
1995 1995
      typename Container::const_iterator it;
1996 1996
    };
1997
    
1998
    /// Alias for \c ValueIt
1999
    typedef ValueIt ValueIterator;
1997 2000

	
1998 2001
    /// \brief Returns an iterator to the first value.
1999 2002
    ///
2000 2003
    /// Returns an STL compatible iterator to the
2001 2004
    /// first value of the map. The values of the
2002 2005
    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
2003 2006
    /// range.
2004
    ValueIterator beginValue() const {
2005
      return ValueIterator(_inv_map.begin());
2007
    ValueIt beginValue() const {
2008
      return ValueIt(_inv_map.begin());
2006 2009
    }
2007 2010

	
2008 2011
    /// \brief Returns an iterator after the last value.
2009 2012
    ///
2010 2013
    /// Returns an STL compatible iterator after the
2011 2014
    /// last value of the map. The values of the
2012 2015
    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
2013 2016
    /// range.
2014
    ValueIterator endValue() const {
2015
      return ValueIterator(_inv_map.end());
2017
    ValueIt endValue() const {
2018
      return ValueIt(_inv_map.end());
2016 2019
    }
2017 2020

	
2018 2021
    /// \brief Sets the value associated with the given key.
2019 2022
    ///
2020 2023
    /// Sets the value associated with the given key.
2021 2024
    void set(const Key& key, const Value& val) {
2022 2025
      Value oldval = Map::operator[](key);
2023 2026
      typename Container::iterator it;
2024 2027
      for (it = _inv_map.equal_range(oldval).first;
2025 2028
           it != _inv_map.equal_range(oldval).second; ++it) {
2026 2029
        if (it->second == key) {
2027 2030
          _inv_map.erase(it);
2028 2031
          break;
2029 2032
        }
2030 2033
      }
2031 2034
      _inv_map.insert(std::make_pair(val, key));
2032 2035
      Map::set(key, val);
2033 2036
    }
2034 2037

	
2035 2038
    /// \brief Returns the value associated with the given key.
2036 2039
    ///
2037 2040
    /// Returns the value associated with the given key.
2038 2041
    typename MapTraits<Map>::ConstReturnValue
2039 2042
    operator[](const Key& key) const {
2040 2043
      return Map::operator[](key);
2041 2044
    }
2042 2045

	
2043 2046
    /// \brief Gives back an item by its value.
2044 2047
    ///
2045 2048
    /// This function gives back an item that is assigned to
2046 2049
    /// the given value or \c INVALID if no such item exists.
2047 2050
    /// If there are more items with the same associated value,
2048 2051
    /// only one of them is returned.
2049 2052
    Key operator()(const Value& val) const {
2050 2053
      typename Container::const_iterator it = _inv_map.find(val);
2051 2054
      return it != _inv_map.end() ? it->second : INVALID;
2052 2055
    }
2053 2056
    
2054 2057
    /// \brief Returns the number of items with the given value.
2055 2058
    ///
2056 2059
    /// This function returns the number of items with the given value
2057 2060
    /// associated with it.
2058 2061
    int count(const Value &val) const {
2059 2062
      return _inv_map.count(val);
2060 2063
    }
2061 2064

	
2062 2065
  protected:
2063 2066

	
2064 2067
    /// \brief Erase the key from the map and the inverse map.
2065 2068
    ///
2066 2069
    /// Erase the key from the map and the inverse map. It is called by the
2067 2070
    /// \c AlterationNotifier.
2068 2071
    virtual void erase(const Key& key) {
2069 2072
      Value val = Map::operator[](key);
2070 2073
      typename Container::iterator it;
2071 2074
      for (it = _inv_map.equal_range(val).first;
2072 2075
           it != _inv_map.equal_range(val).second; ++it) {
2073 2076
        if (it->second == key) {
2074 2077
          _inv_map.erase(it);
2075 2078
          break;
2076 2079
        }
2077 2080
      }
2078 2081
      Map::erase(key);
2079 2082
    }
2080 2083

	
2081 2084
    /// \brief Erase more keys from the map and the inverse map.
2082 2085
    ///
2083 2086
    /// Erase more keys from the map and the inverse map. It is called by the
2084 2087
    /// \c AlterationNotifier.
2085 2088
    virtual void erase(const std::vector<Key>& keys) {
2086 2089
      for (int i = 0; i < int(keys.size()); ++i) {
2087 2090
        Value val = Map::operator[](keys[i]);
2088 2091
        typename Container::iterator it;
2089 2092
        for (it = _inv_map.equal_range(val).first;
2090 2093
             it != _inv_map.equal_range(val).second; ++it) {
2091 2094
          if (it->second == keys[i]) {
2092 2095
            _inv_map.erase(it);
2093 2096
            break;
2094 2097
          }
2095 2098
        }
2096 2099
      }
2097 2100
      Map::erase(keys);
2098 2101
    }
2099 2102

	
2100 2103
    /// \brief Clear the keys from the map and the inverse map.
2101 2104
    ///
2102 2105
    /// Clear the keys from the map and the inverse map. It is called by the
2103 2106
    /// \c AlterationNotifier.
2104 2107
    virtual void clear() {
2105 2108
      _inv_map.clear();
2106 2109
      Map::clear();
2107 2110
    }
2108 2111

	
2109 2112
  public:
2110 2113

	
2111 2114
    /// \brief The inverse map type of CrossRefMap.
2112 2115
    ///
2113 2116
    /// The inverse map type of CrossRefMap. The subscript operator gives
2114 2117
    /// back an item by its value.
2115 2118
    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
2116 2119
    /// \see inverse()
2117 2120
    class InverseMap {
2118 2121
    public:
2119 2122
      /// \brief Constructor
2120 2123
      ///
2121 2124
      /// Constructor of the InverseMap.
2122 2125
      explicit InverseMap(const CrossRefMap& inverted)
2123 2126
        : _inverted(inverted) {}
2124 2127

	
2125 2128
      /// The value type of the InverseMap.
2126 2129
      typedef typename CrossRefMap::Key Value;
2127 2130
      /// The key type of the InverseMap.
2128 2131
      typedef typename CrossRefMap::Value Key;
2129 2132

	
2130 2133
      /// \brief Subscript operator.
2131 2134
      ///
2132 2135
      /// Subscript operator. It gives back an item
2133 2136
      /// that is assigned to the given value or \c INVALID
2134 2137
      /// if no such item exists.
2135 2138
      Value operator[](const Key& key) const {
2136 2139
        return _inverted(key);
2137 2140
      }
2138 2141

	
2139 2142
    private:
2140 2143
      const CrossRefMap& _inverted;
2141 2144
    };
2142 2145

	
2143 2146
    /// \brief Gives back the inverse of the map.
2144 2147
    ///
2145 2148
    /// Gives back the inverse of the CrossRefMap.
2146 2149
    InverseMap inverse() const {
2147 2150
      return InverseMap(*this);
2148 2151
    }
2149 2152

	
2150 2153
  };
2151 2154

	
2152 2155
  /// \brief Provides continuous and unique id for the
2153 2156
  /// items of a graph.
2154 2157
  ///
2155 2158
  /// RangeIdMap provides a unique and continuous
2156 2159
  /// id for each item of a given type (\c Node, \c Arc or
2157 2160
  /// \c Edge) in a graph. This id is
2158 2161
  ///  - \b unique: different items get different ids,
2159 2162
  ///  - \b continuous: the range of the ids is the set of integers
2160 2163
  ///    between 0 and \c n-1, where \c n is the number of the items of
2161 2164
  ///    this type (\c Node, \c Arc or \c Edge).
2162 2165
  ///  - So, the ids can change when deleting an item of the same type.
2163 2166
  ///
2164 2167
  /// Thus this id is not (necessarily) the same as what can get using
2165 2168
  /// the \c id() function of the graph or \ref IdMap.
2166 2169
  /// This map can be inverted with its member class \c InverseMap,
2167 2170
  /// or with the \c operator()() member.
2168 2171
  ///
2169 2172
  /// \tparam GR The graph type.
2170 2173
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
2171 2174
  /// \c GR::Edge).
2172 2175
  ///
2173 2176
  /// \see IdMap
2174 2177
  template <typename GR, typename K>
2175 2178
  class RangeIdMap
2176 2179
    : protected ItemSetTraits<GR, K>::template Map<int>::Type {
2177 2180

	
2178 2181
    typedef typename ItemSetTraits<GR, K>::template Map<int>::Type Map;
2179 2182

	
2180 2183
  public:
2181 2184
    /// The graph type of RangeIdMap.
2182 2185
    typedef GR Graph;
2183 2186
    typedef GR Digraph;
2184 2187
    /// The key type of RangeIdMap (\c Node, \c Arc or \c Edge).
2185 2188
    typedef K Item;
2186 2189
    /// The key type of RangeIdMap (\c Node, \c Arc or \c Edge).
2187 2190
    typedef K Key;
2188 2191
    /// The value type of RangeIdMap.
2189 2192
    typedef int Value;
2190 2193

	
2191 2194
    /// \brief Constructor.
2192 2195
    ///
2193 2196
    /// Constructor.
2194 2197
    explicit RangeIdMap(const Graph& gr) : Map(gr) {
2195 2198
      Item it;
2196 2199
      const typename Map::Notifier* nf = Map::notifier();
2197 2200
      for (nf->first(it); it != INVALID; nf->next(it)) {
2198 2201
        Map::set(it, _inv_map.size());
2199 2202
        _inv_map.push_back(it);
2200 2203
      }
2201 2204
    }
2202 2205

	
2203 2206
  protected:
2204 2207

	
2205 2208
    /// \brief Adds a new key to the map.
2206 2209
    ///
2207 2210
    /// Add a new key to the map. It is called by the
2208 2211
    /// \c AlterationNotifier.
2209 2212
    virtual void add(const Item& item) {
2210 2213
      Map::add(item);
2211 2214
      Map::set(item, _inv_map.size());
2212 2215
      _inv_map.push_back(item);
2213 2216
    }
2214 2217

	
2215 2218
    /// \brief Add more new keys to the map.
2216 2219
    ///
2217 2220
    /// Add more new keys to the map. It is called by the
2218 2221
    /// \c AlterationNotifier.
2219 2222
    virtual void add(const std::vector<Item>& items) {
2220 2223
      Map::add(items);
2221 2224
      for (int i = 0; i < int(items.size()); ++i) {
2222 2225
        Map::set(items[i], _inv_map.size());
2223 2226
        _inv_map.push_back(items[i]);
2224 2227
      }
2225 2228
    }
2226 2229

	
2227 2230
    /// \brief Erase the key from the map.
2228 2231
    ///
2229 2232
    /// Erase the key from the map. It is called by the
2230 2233
    /// \c AlterationNotifier.
2231 2234
    virtual void erase(const Item& item) {
2232 2235
      Map::set(_inv_map.back(), Map::operator[](item));
2233 2236
      _inv_map[Map::operator[](item)] = _inv_map.back();
2234 2237
      _inv_map.pop_back();
2235 2238
      Map::erase(item);
2236 2239
    }
2237 2240

	
2238 2241
    /// \brief Erase more keys from the map.
2239 2242
    ///
2240 2243
    /// Erase more keys from the map. It is called by the
2241 2244
    /// \c AlterationNotifier.
2242 2245
    virtual void erase(const std::vector<Item>& items) {
2243 2246
      for (int i = 0; i < int(items.size()); ++i) {
2244 2247
        Map::set(_inv_map.back(), Map::operator[](items[i]));
2245 2248
        _inv_map[Map::operator[](items[i])] = _inv_map.back();
2246 2249
        _inv_map.pop_back();
2247 2250
      }
2248 2251
      Map::erase(items);
2249 2252
    }
2250 2253

	
2251 2254
    /// \brief Build the unique map.
2252 2255
    ///
2253 2256
    /// Build the unique map. It is called by the
2254 2257
    /// \c AlterationNotifier.
2255 2258
    virtual void build() {
2256 2259
      Map::build();
2257 2260
      Item it;
2258 2261
      const typename Map::Notifier* nf = Map::notifier();
2259 2262
      for (nf->first(it); it != INVALID; nf->next(it)) {
2260 2263
        Map::set(it, _inv_map.size());
2261 2264
        _inv_map.push_back(it);
2262 2265
      }
2263 2266
    }
2264 2267

	
2265 2268
    /// \brief Clear the keys from the map.
2266 2269
    ///
2267 2270
    /// Clear the keys from the map. It is called by the
2268 2271
    /// \c AlterationNotifier.
2269 2272
    virtual void clear() {
2270 2273
      _inv_map.clear();
2271 2274
      Map::clear();
2272 2275
    }
2273 2276

	
2274 2277
  public:
2275 2278

	
2276 2279
    /// \brief Returns the maximal value plus one.
2277 2280
    ///
2278 2281
    /// Returns the maximal value plus one in the map.
2279 2282
    unsigned int size() const {
2280 2283
      return _inv_map.size();
2281 2284
    }
2282 2285

	
2283 2286
    /// \brief Swaps the position of the two items in the map.
2284 2287
    ///
2285 2288
    /// Swaps the position of the two items in the map.
2286 2289
    void swap(const Item& p, const Item& q) {
2287 2290
      int pi = Map::operator[](p);
2288 2291
      int qi = Map::operator[](q);
2289 2292
      Map::set(p, qi);
2290 2293
      _inv_map[qi] = p;
2291 2294
      Map::set(q, pi);
2292 2295
      _inv_map[pi] = q;
2293 2296
    }
2294 2297

	
2295 2298
    /// \brief Gives back the \e range \e id of the item
2296 2299
    ///
2297 2300
    /// Gives back the \e range \e id of the item.
2298 2301
    int operator[](const Item& item) const {
2299 2302
      return Map::operator[](item);
2300 2303
    }
2301 2304

	
2302 2305
    /// \brief Gives back the item belonging to a \e range \e id
2303 2306
    ///
2304 2307
    /// Gives back the item belonging to the given \e range \e id.
2305 2308
    Item operator()(int id) const {
2306 2309
      return _inv_map[id];
2307 2310
    }
2308 2311

	
2309 2312
  private:
2310 2313

	
2311 2314
    typedef std::vector<Item> Container;
2312 2315
    Container _inv_map;
2313 2316

	
2314 2317
  public:
2315 2318

	
2316 2319
    /// \brief The inverse map type of RangeIdMap.
2317 2320
    ///
2318 2321
    /// The inverse map type of RangeIdMap. The subscript operator gives
2319 2322
    /// back an item by its \e range \e id.
2320 2323
    /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept.
2321 2324
    class InverseMap {
2322 2325
    public:
2323 2326
      /// \brief Constructor
2324 2327
      ///
2325 2328
      /// Constructor of the InverseMap.
2326 2329
      explicit InverseMap(const RangeIdMap& inverted)
2327 2330
        : _inverted(inverted) {}
2328 2331

	
2329 2332

	
2330 2333
      /// The value type of the InverseMap.
2331 2334
      typedef typename RangeIdMap::Key Value;
2332 2335
      /// The key type of the InverseMap.
2333 2336
      typedef typename RangeIdMap::Value Key;
2334 2337

	
2335 2338
      /// \brief Subscript operator.
2336 2339
      ///
2337 2340
      /// Subscript operator. It gives back the item
2338 2341
      /// that the given \e range \e id currently belongs to.
2339 2342
      Value operator[](const Key& key) const {
2340 2343
        return _inverted(key);
2341 2344
      }
2342 2345

	
2343 2346
      /// \brief Size of the map.
2344 2347
      ///
2345 2348
      /// Returns the size of the map.
2346 2349
      unsigned int size() const {
2347 2350
        return _inverted.size();
2348 2351
      }
2349 2352

	
2350 2353
    private:
2351 2354
      const RangeIdMap& _inverted;
2352 2355
    };
2353 2356

	
2354 2357
    /// \brief Gives back the inverse of the map.
2355 2358
    ///
2356 2359
    /// Gives back the inverse of the RangeIdMap.
2357 2360
    const InverseMap inverse() const {
2358 2361
      return InverseMap(*this);
2359 2362
    }
2360 2363
  };
2361 2364

	
2362 2365
  /// \brief Dynamic iterable \c bool map.
2363 2366
  ///
2364 2367
  /// This class provides a special graph map type which can store a
2365 2368
  /// \c bool value for graph items (\c Node, \c Arc or \c Edge).
2366 2369
  /// For both \c true and \c false values it is possible to iterate on
2367 2370
  /// the keys mapped to the value.
2368 2371
  ///
2369 2372
  /// This type is a reference map, so it can be modified with the
2370 2373
  /// subscript operator.
2371 2374
  ///
2372 2375
  /// \tparam GR The graph type.
2373 2376
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
2374 2377
  /// \c GR::Edge).
2375 2378
  ///
2376 2379
  /// \see IterableIntMap, IterableValueMap
2377 2380
  /// \see CrossRefMap
2378 2381
  template <typename GR, typename K>
2379 2382
  class IterableBoolMap
2380 2383
    : protected ItemSetTraits<GR, K>::template Map<int>::Type {
2381 2384
  private:
2382 2385
    typedef GR Graph;
2383 2386

	
2384 2387
    typedef typename ItemSetTraits<GR, K>::ItemIt KeyIt;
2385 2388
    typedef typename ItemSetTraits<GR, K>::template Map<int>::Type Parent;
2386 2389

	
2387 2390
    std::vector<K> _array;
2388 2391
    int _sep;
2389 2392

	
2390 2393
  public:
2391 2394

	
2392 2395
    /// Indicates that the map is reference map.
2393 2396
    typedef True ReferenceMapTag;
2394 2397

	
2395 2398
    /// The key type
2396 2399
    typedef K Key;
2397 2400
    /// The value type
2398 2401
    typedef bool Value;
2399 2402
    /// The const reference type.
2400 2403
    typedef const Value& ConstReference;
2401 2404

	
2402 2405
  private:
2403 2406

	
2404 2407
    int position(const Key& key) const {
2405 2408
      return Parent::operator[](key);
2406 2409
    }
2407 2410

	
2408 2411
  public:
2409 2412

	
2410 2413
    /// \brief Reference to the value of the map.
2411 2414
    ///
2412 2415
    /// This class is similar to the \c bool type. It can be converted to
2413 2416
    /// \c bool and it provides the same operators.
2414 2417
    class Reference {
2415 2418
      friend class IterableBoolMap;
2416 2419
    private:
2417 2420
      Reference(IterableBoolMap& map, const Key& key)
2418 2421
        : _key(key), _map(map) {}
2419 2422
    public:
2420 2423

	
2421 2424
      Reference& operator=(const Reference& value) {
2422 2425
        _map.set(_key, static_cast<bool>(value));
2423 2426
         return *this;
2424 2427
      }
2425 2428

	
2426 2429
      operator bool() const {
2427 2430
        return static_cast<const IterableBoolMap&>(_map)[_key];
2428 2431
      }
2429 2432

	
2430 2433
      Reference& operator=(bool value) {
2431 2434
        _map.set(_key, value);
2432 2435
        return *this;
2433 2436
      }
2434 2437
      Reference& operator&=(bool value) {
2435 2438
        _map.set(_key, _map[_key] & value);
2436 2439
        return *this;
2437 2440
      }
2438 2441
      Reference& operator|=(bool value) {
2439 2442
        _map.set(_key, _map[_key] | value);
2440 2443
        return *this;
2441 2444
      }
2442 2445
      Reference& operator^=(bool value) {
2443 2446
        _map.set(_key, _map[_key] ^ value);
2444 2447
        return *this;
2445 2448
      }
2446 2449
    private:
2447 2450
      Key _key;
2448 2451
      IterableBoolMap& _map;
2449 2452
    };
2450 2453

	
2451 2454
    /// \brief Constructor of the map with a default value.
2452 2455
    ///
2453 2456
    /// Constructor of the map with a default value.
2454 2457
    explicit IterableBoolMap(const Graph& graph, bool def = false)
2455 2458
      : Parent(graph) {
2456 2459
      typename Parent::Notifier* nf = Parent::notifier();
2457 2460
      Key it;
2458 2461
      for (nf->first(it); it != INVALID; nf->next(it)) {
2459 2462
        Parent::set(it, _array.size());
2460 2463
        _array.push_back(it);
2461 2464
      }
2462 2465
      _sep = (def ? _array.size() : 0);
2463 2466
    }
2464 2467

	
2465 2468
    /// \brief Const subscript operator of the map.
2466 2469
    ///
2467 2470
    /// Const subscript operator of the map.
2468 2471
    bool operator[](const Key& key) const {
2469 2472
      return position(key) < _sep;
2470 2473
    }
2471 2474

	
2472 2475
    /// \brief Subscript operator of the map.
2473 2476
    ///
2474 2477
    /// Subscript operator of the map.
2475 2478
    Reference operator[](const Key& key) {
2476 2479
      return Reference(*this, key);
2477 2480
    }
2478 2481

	
2479 2482
    /// \brief Set operation of the map.
2480 2483
    ///
2481 2484
    /// Set operation of the map.
2482 2485
    void set(const Key& key, bool value) {
2483 2486
      int pos = position(key);
2484 2487
      if (value) {
2485 2488
        if (pos < _sep) return;
2486 2489
        Key tmp = _array[_sep];
2487 2490
        _array[_sep] = key;
2488 2491
        Parent::set(key, _sep);
2489 2492
        _array[pos] = tmp;
2490 2493
        Parent::set(tmp, pos);
2491 2494
        ++_sep;
2492 2495
      } else {
2493 2496
        if (pos >= _sep) return;
2494 2497
        --_sep;
2495 2498
        Key tmp = _array[_sep];
2496 2499
        _array[_sep] = key;
2497 2500
        Parent::set(key, _sep);
2498 2501
        _array[pos] = tmp;
2499 2502
        Parent::set(tmp, pos);
2500 2503
      }
2501 2504
    }
2502 2505

	
2503 2506
    /// \brief Set all items.
2504 2507
    ///
2505 2508
    /// Set all items in the map.
2506 2509
    /// \note Constant time operation.
2507 2510
    void setAll(bool value) {
2508 2511
      _sep = (value ? _array.size() : 0);
2509 2512
    }
2510 2513

	
2511 2514
    /// \brief Returns the number of the keys mapped to \c true.
2512 2515
    ///
2513 2516
    /// Returns the number of the keys mapped to \c true.
2514 2517
    int trueNum() const {
2515 2518
      return _sep;
2516 2519
    }
2517 2520

	
2518 2521
    /// \brief Returns the number of the keys mapped to \c false.
2519 2522
    ///
2520 2523
    /// Returns the number of the keys mapped to \c false.
2521 2524
    int falseNum() const {
2522 2525
      return _array.size() - _sep;
2523 2526
    }
2524 2527

	
2525 2528
    /// \brief Iterator for the keys mapped to \c true.
2526 2529
    ///
2527 2530
    /// Iterator for the keys mapped to \c true. It works
2528 2531
    /// like a graph item iterator, it can be converted to
2529 2532
    /// the key type of the map, incremented with \c ++ operator, and
2530 2533
    /// if the iterator leaves the last valid key, it will be equal to
2531 2534
    /// \c INVALID.
2532 2535
    class TrueIt : public Key {
2533 2536
    public:
2534 2537
      typedef Key Parent;
2535 2538

	
2536 2539
      /// \brief Creates an iterator.
2537 2540
      ///
2538 2541
      /// Creates an iterator. It iterates on the
2539 2542
      /// keys mapped to \c true.
2540 2543
      /// \param map The IterableBoolMap.
2541 2544
      explicit TrueIt(const IterableBoolMap& map)
2542 2545
        : Parent(map._sep > 0 ? map._array[map._sep - 1] : INVALID),
2543 2546
          _map(&map) {}
2544 2547

	
2545 2548
      /// \brief Invalid constructor \& conversion.
2546 2549
      ///
2547 2550
      /// This constructor initializes the iterator to be invalid.
2548 2551
      /// \sa Invalid for more details.
2549 2552
      TrueIt(Invalid) : Parent(INVALID), _map(0) {}
2550 2553

	
2551 2554
      /// \brief Increment operator.
2552 2555
      ///
2553 2556
      /// Increment operator.
2554 2557
      TrueIt& operator++() {
2555 2558
        int pos = _map->position(*this);
2556 2559
        Parent::operator=(pos > 0 ? _map->_array[pos - 1] : INVALID);
2557 2560
        return *this;
2558 2561
      }
2559 2562

	
2560 2563
    private:
2561 2564
      const IterableBoolMap* _map;
2562 2565
    };
2563 2566

	
2564 2567
    /// \brief Iterator for the keys mapped to \c false.
2565 2568
    ///
2566 2569
    /// Iterator for the keys mapped to \c false. It works
2567 2570
    /// like a graph item iterator, it can be converted to
2568 2571
    /// the key type of the map, incremented with \c ++ operator, and
2569 2572
    /// if the iterator leaves the last valid key, it will be equal to
2570 2573
    /// \c INVALID.
2571 2574
    class FalseIt : public Key {
2572 2575
    public:
2573 2576
      typedef Key Parent;
2574 2577

	
2575 2578
      /// \brief Creates an iterator.
2576 2579
      ///
2577 2580
      /// Creates an iterator. It iterates on the
2578 2581
      /// keys mapped to \c false.
2579 2582
      /// \param map The IterableBoolMap.
2580 2583
      explicit FalseIt(const IterableBoolMap& map)
2581 2584
        : Parent(map._sep < int(map._array.size()) ?
2582 2585
                 map._array.back() : INVALID), _map(&map) {}
2583 2586

	
2584 2587
      /// \brief Invalid constructor \& conversion.
2585 2588
      ///
2586 2589
      /// This constructor initializes the iterator to be invalid.
2587 2590
      /// \sa Invalid for more details.
2588 2591
      FalseIt(Invalid) : Parent(INVALID), _map(0) {}
2589 2592

	
2590 2593
      /// \brief Increment operator.
2591 2594
      ///
2592 2595
      /// Increment operator.
2593 2596
      FalseIt& operator++() {
2594 2597
        int pos = _map->position(*this);
2595 2598
        Parent::operator=(pos > _map->_sep ? _map->_array[pos - 1] : INVALID);
2596 2599
        return *this;
2597 2600
      }
2598 2601

	
2599 2602
    private:
2600 2603
      const IterableBoolMap* _map;
2601 2604
    };
2602 2605

	
2603 2606
    /// \brief Iterator for the keys mapped to a given value.
2604 2607
    ///
2605 2608
    /// Iterator for the keys mapped to a given value. It works
2606 2609
    /// like a graph item iterator, it can be converted to
2607 2610
    /// the key type of the map, incremented with \c ++ operator, and
2608 2611
    /// if the iterator leaves the last valid key, it will be equal to
2609 2612
    /// \c INVALID.
2610 2613
    class ItemIt : public Key {
2611 2614
    public:
2612 2615
      typedef Key Parent;
2613 2616

	
2614 2617
      /// \brief Creates an iterator with a value.
2615 2618
      ///
2616 2619
      /// Creates an iterator with a value. It iterates on the
2617 2620
      /// keys mapped to the given value.
2618 2621
      /// \param map The IterableBoolMap.
2619 2622
      /// \param value The value.
2620 2623
      ItemIt(const IterableBoolMap& map, bool value)
2621 2624
        : Parent(value ? 
2622 2625
                 (map._sep > 0 ?
2623 2626
                  map._array[map._sep - 1] : INVALID) :
2624 2627
                 (map._sep < int(map._array.size()) ?
2625 2628
                  map._array.back() : INVALID)), _map(&map) {}
2626 2629

	
2627 2630
      /// \brief Invalid constructor \& conversion.
2628 2631
      ///
2629 2632
      /// This constructor initializes the iterator to be invalid.
2630 2633
      /// \sa Invalid for more details.
2631 2634
      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
2632 2635

	
2633 2636
      /// \brief Increment operator.
2634 2637
      ///
2635 2638
      /// Increment operator.
2636 2639
      ItemIt& operator++() {
2637 2640
        int pos = _map->position(*this);
2638 2641
        int _sep = pos >= _map->_sep ? _map->_sep : 0;
2639 2642
        Parent::operator=(pos > _sep ? _map->_array[pos - 1] : INVALID);
2640 2643
        return *this;
2641 2644
      }
2642 2645

	
2643 2646
    private:
2644 2647
      const IterableBoolMap* _map;
2645 2648
    };
2646 2649

	
2647 2650
  protected:
2648 2651

	
2649 2652
    virtual void add(const Key& key) {
2650 2653
      Parent::add(key);
2651 2654
      Parent::set(key, _array.size());
2652 2655
      _array.push_back(key);
2653 2656
    }
2654 2657

	
2655 2658
    virtual void add(const std::vector<Key>& keys) {
2656 2659
      Parent::add(keys);
2657 2660
      for (int i = 0; i < int(keys.size()); ++i) {
2658 2661
        Parent::set(keys[i], _array.size());
2659 2662
        _array.push_back(keys[i]);
2660 2663
      }
2661 2664
    }
2662 2665

	
2663 2666
    virtual void erase(const Key& key) {
2664 2667
      int pos = position(key);
2665 2668
      if (pos < _sep) {
2666 2669
        --_sep;
2667 2670
        Parent::set(_array[_sep], pos);
2668 2671
        _array[pos] = _array[_sep];
2669 2672
        Parent::set(_array.back(), _sep);
2670 2673
        _array[_sep] = _array.back();
2671 2674
        _array.pop_back();
2672 2675
      } else {
2673 2676
        Parent::set(_array.back(), pos);
2674 2677
        _array[pos] = _array.back();
2675 2678
        _array.pop_back();
2676 2679
      }
2677 2680
      Parent::erase(key);
2678 2681
    }
2679 2682

	
2680 2683
    virtual void erase(const std::vector<Key>& keys) {
2681 2684
      for (int i = 0; i < int(keys.size()); ++i) {
2682 2685
        int pos = position(keys[i]);
2683 2686
        if (pos < _sep) {
2684 2687
          --_sep;
2685 2688
          Parent::set(_array[_sep], pos);
2686 2689
          _array[pos] = _array[_sep];
2687 2690
          Parent::set(_array.back(), _sep);
2688 2691
          _array[_sep] = _array.back();
2689 2692
          _array.pop_back();
2690 2693
        } else {
2691 2694
          Parent::set(_array.back(), pos);
2692 2695
          _array[pos] = _array.back();
2693 2696
          _array.pop_back();
2694 2697
        }
2695 2698
      }
2696 2699
      Parent::erase(keys);
2697 2700
    }
2698 2701

	
2699 2702
    virtual void build() {
2700 2703
      Parent::build();
2701 2704
      typename Parent::Notifier* nf = Parent::notifier();
2702 2705
      Key it;
2703 2706
      for (nf->first(it); it != INVALID; nf->next(it)) {
2704 2707
        Parent::set(it, _array.size());
2705 2708
        _array.push_back(it);
2706 2709
      }
2707 2710
      _sep = 0;
2708 2711
    }
2709 2712

	
2710 2713
    virtual void clear() {
2711 2714
      _array.clear();
2712 2715
      _sep = 0;
2713 2716
      Parent::clear();
2714 2717
    }
2715 2718

	
2716 2719
  };
2717 2720

	
2718 2721

	
2719 2722
  namespace _maps_bits {
2720 2723
    template <typename Item>
2721 2724
    struct IterableIntMapNode {
2722 2725
      IterableIntMapNode() : value(-1) {}
2723 2726
      IterableIntMapNode(int _value) : value(_value) {}
2724 2727
      Item prev, next;
2725 2728
      int value;
2726 2729
    };
2727 2730
  }
2728 2731

	
2729 2732
  /// \brief Dynamic iterable integer map.
2730 2733
  ///
2731 2734
  /// This class provides a special graph map type which can store an
2732 2735
  /// integer value for graph items (\c Node, \c Arc or \c Edge).
2733 2736
  /// For each non-negative value it is possible to iterate on the keys
2734 2737
  /// mapped to the value.
2735 2738
  ///
2736 2739
  /// This map is intended to be used with small integer values, for which
2737 2740
  /// it is efficient, and supports iteration only for non-negative values.
2738 2741
  /// If you need large values and/or iteration for negative integers,
2739 2742
  /// consider to use \ref IterableValueMap instead.
2740 2743
  ///
2741 2744
  /// This type is a reference map, so it can be modified with the
2742 2745
  /// subscript operator.
2743 2746
  ///
2744 2747
  /// \note The size of the data structure depends on the largest
2745 2748
  /// value in the map.
2746 2749
  ///
2747 2750
  /// \tparam GR The graph type.
2748 2751
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
2749 2752
  /// \c GR::Edge).
2750 2753
  ///
2751 2754
  /// \see IterableBoolMap, IterableValueMap
2752 2755
  /// \see CrossRefMap
2753 2756
  template <typename GR, typename K>
2754 2757
  class IterableIntMap
2755 2758
    : protected ItemSetTraits<GR, K>::
2756 2759
        template Map<_maps_bits::IterableIntMapNode<K> >::Type {
2757 2760
  public:
2758 2761
    typedef typename ItemSetTraits<GR, K>::
2759 2762
      template Map<_maps_bits::IterableIntMapNode<K> >::Type Parent;
2760 2763

	
2761 2764
    /// The key type
2762 2765
    typedef K Key;
2763 2766
    /// The value type
2764 2767
    typedef int Value;
2765 2768
    /// The graph type
2766 2769
    typedef GR Graph;
2767 2770

	
2768 2771
    /// \brief Constructor of the map.
2769 2772
    ///
2770 2773
    /// Constructor of the map. It sets all values to -1.
2771 2774
    explicit IterableIntMap(const Graph& graph)
2772 2775
      : Parent(graph) {}
2773 2776

	
2774 2777
    /// \brief Constructor of the map with a given value.
2775 2778
    ///
2776 2779
    /// Constructor of the map with a given value.
2777 2780
    explicit IterableIntMap(const Graph& graph, int value)
2778 2781
      : Parent(graph, _maps_bits::IterableIntMapNode<K>(value)) {
2779 2782
      if (value >= 0) {
2780 2783
        for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
2781 2784
          lace(it);
2782 2785
        }
2783 2786
      }
2784 2787
    }
2785 2788

	
2786 2789
  private:
2787 2790

	
2788 2791
    void unlace(const Key& key) {
2789 2792
      typename Parent::Value& node = Parent::operator[](key);
2790 2793
      if (node.value < 0) return;
2791 2794
      if (node.prev != INVALID) {
2792 2795
        Parent::operator[](node.prev).next = node.next;
2793 2796
      } else {
2794 2797
        _first[node.value] = node.next;
2795 2798
      }
2796 2799
      if (node.next != INVALID) {
2797 2800
        Parent::operator[](node.next).prev = node.prev;
2798 2801
      }
2799 2802
      while (!_first.empty() && _first.back() == INVALID) {
2800 2803
        _first.pop_back();
2801 2804
      }
2802 2805
    }
2803 2806

	
2804 2807
    void lace(const Key& key) {
2805 2808
      typename Parent::Value& node = Parent::operator[](key);
2806 2809
      if (node.value < 0) return;
2807 2810
      if (node.value >= int(_first.size())) {
2808 2811
        _first.resize(node.value + 1, INVALID);
2809 2812
      }
2810 2813
      node.prev = INVALID;
2811 2814
      node.next = _first[node.value];
2812 2815
      if (node.next != INVALID) {
2813 2816
        Parent::operator[](node.next).prev = key;
2814 2817
      }
2815 2818
      _first[node.value] = key;
2816 2819
    }
2817 2820

	
2818 2821
  public:
2819 2822

	
2820 2823
    /// Indicates that the map is reference map.
2821 2824
    typedef True ReferenceMapTag;
2822 2825

	
2823 2826
    /// \brief Reference to the value of the map.
2824 2827
    ///
2825 2828
    /// This class is similar to the \c int type. It can
2826 2829
    /// be converted to \c int and it has the same operators.
2827 2830
    class Reference {
2828 2831
      friend class IterableIntMap;
2829 2832
    private:
2830 2833
      Reference(IterableIntMap& map, const Key& key)
2831 2834
        : _key(key), _map(map) {}
2832 2835
    public:
2833 2836

	
2834 2837
      Reference& operator=(const Reference& value) {
2835 2838
        _map.set(_key, static_cast<const int&>(value));
2836 2839
         return *this;
2837 2840
      }
2838 2841

	
2839 2842
      operator const int&() const {
2840 2843
        return static_cast<const IterableIntMap&>(_map)[_key];
2841 2844
      }
2842 2845

	
2843 2846
      Reference& operator=(int value) {
2844 2847
        _map.set(_key, value);
2845 2848
        return *this;
2846 2849
      }
2847 2850
      Reference& operator++() {
2848 2851
        _map.set(_key, _map[_key] + 1);
2849 2852
        return *this;
2850 2853
      }
2851 2854
      int operator++(int) {
2852 2855
        int value = _map[_key];
2853 2856
        _map.set(_key, value + 1);
2854 2857
        return value;
2855 2858
      }
2856 2859
      Reference& operator--() {
2857 2860
        _map.set(_key, _map[_key] - 1);
2858 2861
        return *this;
2859 2862
      }
2860 2863
      int operator--(int) {
2861 2864
        int value = _map[_key];
2862 2865
        _map.set(_key, value - 1);
2863 2866
        return value;
2864 2867
      }
2865 2868
      Reference& operator+=(int value) {
2866 2869
        _map.set(_key, _map[_key] + value);
2867 2870
        return *this;
2868 2871
      }
2869 2872
      Reference& operator-=(int value) {
2870 2873
        _map.set(_key, _map[_key] - value);
2871 2874
        return *this;
2872 2875
      }
2873 2876
      Reference& operator*=(int value) {
2874 2877
        _map.set(_key, _map[_key] * value);
2875 2878
        return *this;
2876 2879
      }
2877 2880
      Reference& operator/=(int value) {
2878 2881
        _map.set(_key, _map[_key] / value);
2879 2882
        return *this;
2880 2883
      }
2881 2884
      Reference& operator%=(int value) {
2882 2885
        _map.set(_key, _map[_key] % value);
2883 2886
        return *this;
2884 2887
      }
2885 2888
      Reference& operator&=(int value) {
2886 2889
        _map.set(_key, _map[_key] & value);
2887 2890
        return *this;
2888 2891
      }
2889 2892
      Reference& operator|=(int value) {
2890 2893
        _map.set(_key, _map[_key] | value);
2891 2894
        return *this;
2892 2895
      }
2893 2896
      Reference& operator^=(int value) {
2894 2897
        _map.set(_key, _map[_key] ^ value);
2895 2898
        return *this;
2896 2899
      }
2897 2900
      Reference& operator<<=(int value) {
2898 2901
        _map.set(_key, _map[_key] << value);
2899 2902
        return *this;
2900 2903
      }
2901 2904
      Reference& operator>>=(int value) {
2902 2905
        _map.set(_key, _map[_key] >> value);
2903 2906
        return *this;
2904 2907
      }
2905 2908

	
2906 2909
    private:
2907 2910
      Key _key;
2908 2911
      IterableIntMap& _map;
2909 2912
    };
2910 2913

	
2911 2914
    /// The const reference type.
2912 2915
    typedef const Value& ConstReference;
2913 2916

	
2914 2917
    /// \brief Gives back the maximal value plus one.
2915 2918
    ///
2916 2919
    /// Gives back the maximal value plus one.
2917 2920
    int size() const {
2918 2921
      return _first.size();
2919 2922
    }
2920 2923

	
2921 2924
    /// \brief Set operation of the map.
2922 2925
    ///
2923 2926
    /// Set operation of the map.
2924 2927
    void set(const Key& key, const Value& value) {
2925 2928
      unlace(key);
2926 2929
      Parent::operator[](key).value = value;
2927 2930
      lace(key);
2928 2931
    }
2929 2932

	
2930 2933
    /// \brief Const subscript operator of the map.
2931 2934
    ///
2932 2935
    /// Const subscript operator of the map.
2933 2936
    const Value& operator[](const Key& key) const {
2934 2937
      return Parent::operator[](key).value;
2935 2938
    }
2936 2939

	
2937 2940
    /// \brief Subscript operator of the map.
2938 2941
    ///
2939 2942
    /// Subscript operator of the map.
2940 2943
    Reference operator[](const Key& key) {
2941 2944
      return Reference(*this, key);
2942 2945
    }
2943 2946

	
2944 2947
    /// \brief Iterator for the keys with the same value.
2945 2948
    ///
2946 2949
    /// Iterator for the keys with the same value. It works
2947 2950
    /// like a graph item iterator, it can be converted to
2948 2951
    /// the item type of the map, incremented with \c ++ operator, and
2949 2952
    /// if the iterator leaves the last valid item, it will be equal to
2950 2953
    /// \c INVALID.
2951 2954
    class ItemIt : public Key {
2952 2955
    public:
2953 2956
      typedef Key Parent;
2954 2957

	
2955 2958
      /// \brief Invalid constructor \& conversion.
2956 2959
      ///
2957 2960
      /// This constructor initializes the iterator to be invalid.
2958 2961
      /// \sa Invalid for more details.
2959 2962
      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
2960 2963

	
2961 2964
      /// \brief Creates an iterator with a value.
2962 2965
      ///
2963 2966
      /// Creates an iterator with a value. It iterates on the
2964 2967
      /// keys mapped to the given value.
2965 2968
      /// \param map The IterableIntMap.
2966 2969
      /// \param value The value.
2967 2970
      ItemIt(const IterableIntMap& map, int value) : _map(&map) {
2968 2971
        if (value < 0 || value >= int(_map->_first.size())) {
2969 2972
          Parent::operator=(INVALID);
2970 2973
        } else {
2971 2974
          Parent::operator=(_map->_first[value]);
2972 2975
        }
2973 2976
      }
2974 2977

	
2975 2978
      /// \brief Increment operator.
2976 2979
      ///
2977 2980
      /// Increment operator.
2978 2981
      ItemIt& operator++() {
2979 2982
        Parent::operator=(_map->IterableIntMap::Parent::
2980 2983
                          operator[](static_cast<Parent&>(*this)).next);
2981 2984
        return *this;
2982 2985
      }
2983 2986

	
2984 2987
    private:
2985 2988
      const IterableIntMap* _map;
2986 2989
    };
2987 2990

	
2988 2991
  protected:
2989 2992

	
2990 2993
    virtual void erase(const Key& key) {
2991 2994
      unlace(key);
2992 2995
      Parent::erase(key);
2993 2996
    }
2994 2997

	
2995 2998
    virtual void erase(const std::vector<Key>& keys) {
2996 2999
      for (int i = 0; i < int(keys.size()); ++i) {
2997 3000
        unlace(keys[i]);
2998 3001
      }
2999 3002
      Parent::erase(keys);
3000 3003
    }
3001 3004

	
3002 3005
    virtual void clear() {
3003 3006
      _first.clear();
3004 3007
      Parent::clear();
3005 3008
    }
3006 3009

	
3007 3010
  private:
3008 3011
    std::vector<Key> _first;
3009 3012
  };
3010 3013

	
3011 3014
  namespace _maps_bits {
3012 3015
    template <typename Item, typename Value>
3013 3016
    struct IterableValueMapNode {
3014 3017
      IterableValueMapNode(Value _value = Value()) : value(_value) {}
3015 3018
      Item prev, next;
3016 3019
      Value value;
3017 3020
    };
3018 3021
  }
3019 3022

	
3020 3023
  /// \brief Dynamic iterable map for comparable values.
3021 3024
  ///
3022 3025
  /// This class provides a special graph map type which can store a
3023 3026
  /// comparable value for graph items (\c Node, \c Arc or \c Edge).
3024 3027
  /// For each value it is possible to iterate on the keys mapped to
3025 3028
  /// the value (\c ItemIt), and the values of the map can be accessed
3026
  /// with an STL compatible forward iterator (\c ValueIterator).
3029
  /// with an STL compatible forward iterator (\c ValueIt).
3027 3030
  /// The map stores a linked list for each value, which contains
3028 3031
  /// the items mapped to the value, and the used values are stored
3029 3032
  /// in balanced binary tree (\c std::map).
3030 3033
  ///
3031 3034
  /// \ref IterableBoolMap and \ref IterableIntMap are similar classes
3032 3035
  /// specialized for \c bool and \c int values, respectively.
3033 3036
  ///
3034 3037
  /// This type is not reference map, so it cannot be modified with
3035 3038
  /// the subscript operator.
3036 3039
  ///
3037 3040
  /// \tparam GR The graph type.
3038 3041
  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
3039 3042
  /// \c GR::Edge).
3040 3043
  /// \tparam V The value type of the map. It can be any comparable
3041 3044
  /// value type.
3042 3045
  ///
3043 3046
  /// \see IterableBoolMap, IterableIntMap
3044 3047
  /// \see CrossRefMap
3045 3048
  template <typename GR, typename K, typename V>
3046 3049
  class IterableValueMap
3047 3050
    : protected ItemSetTraits<GR, K>::
3048 3051
        template Map<_maps_bits::IterableValueMapNode<K, V> >::Type {
3049 3052
  public:
3050 3053
    typedef typename ItemSetTraits<GR, K>::
3051 3054
      template Map<_maps_bits::IterableValueMapNode<K, V> >::Type Parent;
3052 3055

	
3053 3056
    /// The key type
3054 3057
    typedef K Key;
3055 3058
    /// The value type
3056 3059
    typedef V Value;
3057 3060
    /// The graph type
3058 3061
    typedef GR Graph;
3059 3062

	
3060 3063
  public:
3061 3064

	
3062 3065
    /// \brief Constructor of the map with a given value.
3063 3066
    ///
3064 3067
    /// Constructor of the map with a given value.
3065 3068
    explicit IterableValueMap(const Graph& graph,
3066 3069
                              const Value& value = Value())
3067 3070
      : Parent(graph, _maps_bits::IterableValueMapNode<K, V>(value)) {
3068 3071
      for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
3069 3072
        lace(it);
3070 3073
      }
3071 3074
    }
3072 3075

	
3073 3076
  protected:
3074 3077

	
3075 3078
    void unlace(const Key& key) {
3076 3079
      typename Parent::Value& node = Parent::operator[](key);
3077 3080
      if (node.prev != INVALID) {
3078 3081
        Parent::operator[](node.prev).next = node.next;
3079 3082
      } else {
3080 3083
        if (node.next != INVALID) {
3081 3084
          _first[node.value] = node.next;
3082 3085
        } else {
3083 3086
          _first.erase(node.value);
3084 3087
        }
3085 3088
      }
3086 3089
      if (node.next != INVALID) {
3087 3090
        Parent::operator[](node.next).prev = node.prev;
3088 3091
      }
3089 3092
    }
3090 3093

	
3091 3094
    void lace(const Key& key) {
3092 3095
      typename Parent::Value& node = Parent::operator[](key);
3093 3096
      typename std::map<Value, Key>::iterator it = _first.find(node.value);
3094 3097
      if (it == _first.end()) {
3095 3098
        node.prev = node.next = INVALID;
3096 3099
        _first.insert(std::make_pair(node.value, key));
3097 3100
      } else {
3098 3101
        node.prev = INVALID;
3099 3102
        node.next = it->second;
3100 3103
        if (node.next != INVALID) {
3101 3104
          Parent::operator[](node.next).prev = key;
3102 3105
        }
3103 3106
        it->second = key;
3104 3107
      }
3105 3108
    }
3106 3109

	
3107 3110
  public:
3108 3111

	
3109 3112
    /// \brief Forward iterator for values.
3110 3113
    ///
3111 3114
    /// This iterator is an STL compatible forward
3112 3115
    /// iterator on the values of the map. The values can
3113 3116
    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
3114
    class ValueIterator
3117
    class ValueIt
3115 3118
      : public std::iterator<std::forward_iterator_tag, Value> {
3116 3119
      friend class IterableValueMap;
3117 3120
    private:
3118
      ValueIterator(typename std::map<Value, Key>::const_iterator _it)
3121
      ValueIt(typename std::map<Value, Key>::const_iterator _it)
3119 3122
        : it(_it) {}
3120 3123
    public:
3121 3124

	
3122 3125
      /// Constructor
3123
      ValueIterator() {}
3126
      ValueIt() {}
3124 3127

	
3125 3128
      /// \e
3126
      ValueIterator& operator++() { ++it; return *this; }
3129
      ValueIt& operator++() { ++it; return *this; }
3127 3130
      /// \e
3128
      ValueIterator operator++(int) {
3129
        ValueIterator tmp(*this);
3131
      ValueIt operator++(int) {
3132
        ValueIt tmp(*this);
3130 3133
        operator++();
3131 3134
        return tmp;
3132 3135
      }
3133 3136

	
3134 3137
      /// \e
3135 3138
      const Value& operator*() const { return it->first; }
3136 3139
      /// \e
3137 3140
      const Value* operator->() const { return &(it->first); }
3138 3141

	
3139 3142
      /// \e
3140
      bool operator==(ValueIterator jt) const { return it == jt.it; }
3143
      bool operator==(ValueIt jt) const { return it == jt.it; }
3141 3144
      /// \e
3142
      bool operator!=(ValueIterator jt) const { return it != jt.it; }
3145
      bool operator!=(ValueIt jt) const { return it != jt.it; }
3143 3146

	
3144 3147
    private:
3145 3148
      typename std::map<Value, Key>::const_iterator it;
3146 3149
    };
3147 3150

	
3148 3151
    /// \brief Returns an iterator to the first value.
3149 3152
    ///
3150 3153
    /// Returns an STL compatible iterator to the
3151 3154
    /// first value of the map. The values of the
3152 3155
    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
3153 3156
    /// range.
3154
    ValueIterator beginValue() const {
3155
      return ValueIterator(_first.begin());
3157
    ValueIt beginValue() const {
3158
      return ValueIt(_first.begin());
3156 3159
    }
3157 3160

	
3158 3161
    /// \brief Returns an iterator after the last value.
3159 3162
    ///
3160 3163
    /// Returns an STL compatible iterator after the
3161 3164
    /// last value of the map. The values of the
3162 3165
    /// map can be accessed in the <tt>[beginValue, endValue)</tt>
3163 3166
    /// range.
3164
    ValueIterator endValue() const {
3165
      return ValueIterator(_first.end());
3167
    ValueIt endValue() const {
3168
      return ValueIt(_first.end());
3166 3169
    }
3167 3170

	
3168 3171
    /// \brief Set operation of the map.
3169 3172
    ///
3170 3173
    /// Set operation of the map.
3171 3174
    void set(const Key& key, const Value& value) {
3172 3175
      unlace(key);
3173 3176
      Parent::operator[](key).value = value;
3174 3177
      lace(key);
3175 3178
    }
3176 3179

	
3177 3180
    /// \brief Const subscript operator of the map.
3178 3181
    ///
3179 3182
    /// Const subscript operator of the map.
3180 3183
    const Value& operator[](const Key& key) const {
3181 3184
      return Parent::operator[](key).value;
3182 3185
    }
3183 3186

	
3184 3187
    /// \brief Iterator for the keys with the same value.
3185 3188
    ///
3186 3189
    /// Iterator for the keys with the same value. It works
3187 3190
    /// like a graph item iterator, it can be converted to
3188 3191
    /// the item type of the map, incremented with \c ++ operator, and
3189 3192
    /// if the iterator leaves the last valid item, it will be equal to
3190 3193
    /// \c INVALID.
3191 3194
    class ItemIt : public Key {
3192 3195
    public:
3193 3196
      typedef Key Parent;
3194 3197

	
3195 3198
      /// \brief Invalid constructor \& conversion.
3196 3199
      ///
3197 3200
      /// This constructor initializes the iterator to be invalid.
3198 3201
      /// \sa Invalid for more details.
3199 3202
      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
3200 3203

	
3201 3204
      /// \brief Creates an iterator with a value.
3202 3205
      ///
3203 3206
      /// Creates an iterator with a value. It iterates on the
3204 3207
      /// keys which have the given value.
3205 3208
      /// \param map The IterableValueMap
3206 3209
      /// \param value The value
3207 3210
      ItemIt(const IterableValueMap& map, const Value& value) : _map(&map) {
3208 3211
        typename std::map<Value, Key>::const_iterator it =
3209 3212
          map._first.find(value);
3210 3213
        if (it == map._first.end()) {
3211 3214
          Parent::operator=(INVALID);
3212 3215
        } else {
3213 3216
          Parent::operator=(it->second);
3214 3217
        }
3215 3218
      }
3216 3219

	
3217 3220
      /// \brief Increment operator.
3218 3221
      ///
3219 3222
      /// Increment Operator.
3220 3223
      ItemIt& operator++() {
3221 3224
        Parent::operator=(_map->IterableValueMap::Parent::
3222 3225
                          operator[](static_cast<Parent&>(*this)).next);
3223 3226
        return *this;
3224 3227
      }
3225 3228

	
3226 3229

	
3227 3230
    private:
3228 3231
      const IterableValueMap* _map;
3229 3232
    };
3230 3233

	
3231 3234
  protected:
3232 3235

	
3233 3236
    virtual void add(const Key& key) {
3234 3237
      Parent::add(key);
3235 3238
      unlace(key);
3236 3239
    }
3237 3240

	
3238 3241
    virtual void add(const std::vector<Key>& keys) {
3239 3242
      Parent::add(keys);
3240 3243
      for (int i = 0; i < int(keys.size()); ++i) {
3241 3244
        lace(keys[i]);
3242 3245
      }
3243 3246
    }
3244 3247

	
3245 3248
    virtual void erase(const Key& key) {
3246 3249
      unlace(key);
3247 3250
      Parent::erase(key);
3248 3251
    }
3249 3252

	
3250 3253
    virtual void erase(const std::vector<Key>& keys) {
3251 3254
      for (int i = 0; i < int(keys.size()); ++i) {
3252 3255
        unlace(keys[i]);
3253 3256
      }
3254 3257
      Parent::erase(keys);
3255 3258
    }
3256 3259

	
3257 3260
    virtual void build() {
3258 3261
      Parent::build();
3259 3262
      for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
3260 3263
        lace(it);
3261 3264
      }
3262 3265
    }
3263 3266

	
3264 3267
    virtual void clear() {
3265 3268
      _first.clear();
3266 3269
      Parent::clear();
3267 3270
    }
3268 3271

	
3269 3272
  private:
3270 3273
    std::map<Value, Key> _first;
3271 3274
  };
3272 3275

	
3273 3276
  /// \brief Map of the source nodes of arcs in a digraph.
3274 3277
  ///
3275 3278
  /// SourceMap provides access for the source node of each arc in a digraph,
3276 3279
  /// which is returned by the \c source() function of the digraph.
3277 3280
  /// \tparam GR The digraph type.
3278 3281
  /// \see TargetMap
3279 3282
  template <typename GR>
3280 3283
  class SourceMap {
3281 3284
  public:
3282 3285

	
3283
    ///\e
3286
    /// The key type (the \c Arc type of the digraph).
3284 3287
    typedef typename GR::Arc Key;
3285
    ///\e
3288
    /// The value type (the \c Node type of the digraph).
3286 3289
    typedef typename GR::Node Value;
3287 3290

	
3288 3291
    /// \brief Constructor
3289 3292
    ///
3290 3293
    /// Constructor.
3291 3294
    /// \param digraph The digraph that the map belongs to.
3292 3295
    explicit SourceMap(const GR& digraph) : _graph(digraph) {}
3293 3296

	
3294 3297
    /// \brief Returns the source node of the given arc.
3295 3298
    ///
3296 3299
    /// Returns the source node of the given arc.
3297 3300
    Value operator[](const Key& arc) const {
3298 3301
      return _graph.source(arc);
3299 3302
    }
3300 3303

	
3301 3304
  private:
3302 3305
    const GR& _graph;
3303 3306
  };
3304 3307

	
3305 3308
  /// \brief Returns a \c SourceMap class.
3306 3309
  ///
3307 3310
  /// This function just returns an \c SourceMap class.
3308 3311
  /// \relates SourceMap
3309 3312
  template <typename GR>
3310 3313
  inline SourceMap<GR> sourceMap(const GR& graph) {
3311 3314
    return SourceMap<GR>(graph);
3312 3315
  }
3313 3316

	
3314 3317
  /// \brief Map of the target nodes of arcs in a digraph.
3315 3318
  ///
3316 3319
  /// TargetMap provides access for the target node of each arc in a digraph,
3317 3320
  /// which is returned by the \c target() function of the digraph.
3318 3321
  /// \tparam GR The digraph type.
3319 3322
  /// \see SourceMap
3320 3323
  template <typename GR>
3321 3324
  class TargetMap {
3322 3325
  public:
3323 3326

	
3324
    ///\e
3327
    /// The key type (the \c Arc type of the digraph).
3325 3328
    typedef typename GR::Arc Key;
3326
    ///\e
3329
    /// The value type (the \c Node type of the digraph).
3327 3330
    typedef typename GR::Node Value;
3328 3331

	
3329 3332
    /// \brief Constructor
3330 3333
    ///
3331 3334
    /// Constructor.
3332 3335
    /// \param digraph The digraph that the map belongs to.
3333 3336
    explicit TargetMap(const GR& digraph) : _graph(digraph) {}
3334 3337

	
3335 3338
    /// \brief Returns the target node of the given arc.
3336 3339
    ///
3337 3340
    /// Returns the target node of the given arc.
3338 3341
    Value operator[](const Key& e) const {
3339 3342
      return _graph.target(e);
3340 3343
    }
3341 3344

	
3342 3345
  private:
3343 3346
    const GR& _graph;
3344 3347
  };
3345 3348

	
3346 3349
  /// \brief Returns a \c TargetMap class.
3347 3350
  ///
3348 3351
  /// This function just returns a \c TargetMap class.
3349 3352
  /// \relates TargetMap
3350 3353
  template <typename GR>
3351 3354
  inline TargetMap<GR> targetMap(const GR& graph) {
3352 3355
    return TargetMap<GR>(graph);
3353 3356
  }
3354 3357

	
3355 3358
  /// \brief Map of the "forward" directed arc view of edges in a graph.
3356 3359
  ///
3357 3360
  /// ForwardMap provides access for the "forward" directed arc view of
3358 3361
  /// each edge in a graph, which is returned by the \c direct() function
3359 3362
  /// of the graph with \c true parameter.
3360 3363
  /// \tparam GR The graph type.
3361 3364
  /// \see BackwardMap
3362 3365
  template <typename GR>
3363 3366
  class ForwardMap {
3364 3367
  public:
3365 3368

	
3369
    /// The key type (the \c Edge type of the digraph).
3370
    typedef typename GR::Edge Key;
3371
    /// The value type (the \c Arc type of the digraph).
3366 3372
    typedef typename GR::Arc Value;
3367
    typedef typename GR::Edge Key;
3368 3373

	
3369 3374
    /// \brief Constructor
3370 3375
    ///
3371 3376
    /// Constructor.
3372 3377
    /// \param graph The graph that the map belongs to.
3373 3378
    explicit ForwardMap(const GR& graph) : _graph(graph) {}
3374 3379

	
3375 3380
    /// \brief Returns the "forward" directed arc view of the given edge.
3376 3381
    ///
3377 3382
    /// Returns the "forward" directed arc view of the given edge.
3378 3383
    Value operator[](const Key& key) const {
3379 3384
      return _graph.direct(key, true);
3380 3385
    }
3381 3386

	
3382 3387
  private:
3383 3388
    const GR& _graph;
3384 3389
  };
3385 3390

	
3386 3391
  /// \brief Returns a \c ForwardMap class.
3387 3392
  ///
3388 3393
  /// This function just returns an \c ForwardMap class.
3389 3394
  /// \relates ForwardMap
3390 3395
  template <typename GR>
3391 3396
  inline ForwardMap<GR> forwardMap(const GR& graph) {
3392 3397
    return ForwardMap<GR>(graph);
3393 3398
  }
3394 3399

	
3395 3400
  /// \brief Map of the "backward" directed arc view of edges in a graph.
3396 3401
  ///
3397 3402
  /// BackwardMap provides access for the "backward" directed arc view of
3398 3403
  /// each edge in a graph, which is returned by the \c direct() function
3399 3404
  /// of the graph with \c false parameter.
3400 3405
  /// \tparam GR The graph type.
3401 3406
  /// \see ForwardMap
3402 3407
  template <typename GR>
3403 3408
  class BackwardMap {
3404 3409
  public:
3405 3410

	
3411
    /// The key type (the \c Edge type of the digraph).
3412
    typedef typename GR::Edge Key;
3413
    /// The value type (the \c Arc type of the digraph).
3406 3414
    typedef typename GR::Arc Value;
3407
    typedef typename GR::Edge Key;
3408 3415

	
3409 3416
    /// \brief Constructor
3410 3417
    ///
3411 3418
    /// Constructor.
3412 3419
    /// \param graph The graph that the map belongs to.
3413 3420
    explicit BackwardMap(const GR& graph) : _graph(graph) {}
3414 3421

	
3415 3422
    /// \brief Returns the "backward" directed arc view of the given edge.
3416 3423
    ///
3417 3424
    /// Returns the "backward" directed arc view of the given edge.
3418 3425
    Value operator[](const Key& key) const {
3419 3426
      return _graph.direct(key, false);
3420 3427
    }
3421 3428

	
3422 3429
  private:
3423 3430
    const GR& _graph;
3424 3431
  };
3425 3432

	
3426 3433
  /// \brief Returns a \c BackwardMap class
3427 3434

	
3428 3435
  /// This function just returns a \c BackwardMap class.
3429 3436
  /// \relates BackwardMap
3430 3437
  template <typename GR>
3431 3438
  inline BackwardMap<GR> backwardMap(const GR& graph) {
3432 3439
    return BackwardMap<GR>(graph);
3433 3440
  }
3434 3441

	
3435 3442
  /// \brief Map of the in-degrees of nodes in a digraph.
3436 3443
  ///
3437 3444
  /// This map returns the in-degree of a node. Once it is constructed,
3438 3445
  /// the degrees are stored in a standard \c NodeMap, so each query is done
3439 3446
  /// in constant time. On the other hand, the values are updated automatically
3440 3447
  /// whenever the digraph changes.
3441 3448
  ///
3442 3449
  /// \warning Besides \c addNode() and \c addArc(), a digraph structure
3443 3450
  /// may provide alternative ways to modify the digraph.
3444 3451
  /// The correct behavior of InDegMap is not guarantied if these additional
3445 3452
  /// features are used. For example the functions
3446 3453
  /// \ref ListDigraph::changeSource() "changeSource()",
3447 3454
  /// \ref ListDigraph::changeTarget() "changeTarget()" and
3448 3455
  /// \ref ListDigraph::reverseArc() "reverseArc()"
3449 3456
  /// of \ref ListDigraph will \e not update the degree values correctly.
3450 3457
  ///
3451 3458
  /// \sa OutDegMap
3452 3459
  template <typename GR>
3453 3460
  class InDegMap
3454 3461
    : protected ItemSetTraits<GR, typename GR::Arc>
3455 3462
      ::ItemNotifier::ObserverBase {
3456 3463

	
3457 3464
  public:
3458 3465

	
3459 3466
    /// The graph type of InDegMap
3460 3467
    typedef GR Graph;
3461 3468
    typedef GR Digraph;
3462 3469
    /// The key type
3463 3470
    typedef typename Digraph::Node Key;
3464 3471
    /// The value type
3465 3472
    typedef int Value;
3466 3473

	
3467 3474
    typedef typename ItemSetTraits<Digraph, typename Digraph::Arc>
3468 3475
    ::ItemNotifier::ObserverBase Parent;
3469 3476

	
3470 3477
  private:
3471 3478

	
3472 3479
    class AutoNodeMap
3473 3480
      : public ItemSetTraits<Digraph, Key>::template Map<int>::Type {
3474 3481
    public:
3475 3482

	
3476 3483
      typedef typename ItemSetTraits<Digraph, Key>::
3477 3484
      template Map<int>::Type Parent;
3478 3485

	
3479 3486
      AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {}
3480 3487

	
3481 3488
      virtual void add(const Key& key) {
3482 3489
        Parent::add(key);
3483 3490
        Parent::set(key, 0);
3484 3491
      }
3485 3492

	
3486 3493
      virtual void add(const std::vector<Key>& keys) {
3487 3494
        Parent::add(keys);
3488 3495
        for (int i = 0; i < int(keys.size()); ++i) {
3489 3496
          Parent::set(keys[i], 0);
3490 3497
        }
3491 3498
      }
3492 3499

	
3493 3500
      virtual void build() {
3494 3501
        Parent::build();
3495 3502
        Key it;
3496 3503
        typename Parent::Notifier* nf = Parent::notifier();
3497 3504
        for (nf->first(it); it != INVALID; nf->next(it)) {
3498 3505
          Parent::set(it, 0);
3499 3506
        }
3500 3507
      }
3501 3508
    };
3502 3509

	
3503 3510
  public:
3504 3511

	
3505 3512
    /// \brief Constructor.
3506 3513
    ///
3507 3514
    /// Constructor for creating an in-degree map.
3508 3515
    explicit InDegMap(const Digraph& graph)
3509 3516
      : _digraph(graph), _deg(graph) {
3510 3517
      Parent::attach(_digraph.notifier(typename Digraph::Arc()));
3511 3518

	
3512 3519
      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
3513 3520
        _deg[it] = countInArcs(_digraph, it);
3514 3521
      }
3515 3522
    }
3516 3523

	
3517 3524
    /// \brief Gives back the in-degree of a Node.
3518 3525
    ///
3519 3526
    /// Gives back the in-degree of a Node.
3520 3527
    int operator[](const Key& key) const {
3521 3528
      return _deg[key];
3522 3529
    }
3523 3530

	
3524 3531
  protected:
3525 3532

	
3526 3533
    typedef typename Digraph::Arc Arc;
3527 3534

	
3528 3535
    virtual void add(const Arc& arc) {
3529 3536
      ++_deg[_digraph.target(arc)];
3530 3537
    }
3531 3538

	
3532 3539
    virtual void add(const std::vector<Arc>& arcs) {
3533 3540
      for (int i = 0; i < int(arcs.size()); ++i) {
3534 3541
        ++_deg[_digraph.target(arcs[i])];
3535 3542
      }
3536 3543
    }
3537 3544

	
3538 3545
    virtual void erase(const Arc& arc) {
3539 3546
      --_deg[_digraph.target(arc)];
3540 3547
    }
3541 3548

	
3542 3549
    virtual void erase(const std::vector<Arc>& arcs) {
3543 3550
      for (int i = 0; i < int(arcs.size()); ++i) {
3544 3551
        --_deg[_digraph.target(arcs[i])];
3545 3552
      }
3546 3553
    }
3547 3554

	
3548 3555
    virtual void build() {
3549 3556
      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
3550 3557
        _deg[it] = countInArcs(_digraph, it);
3551 3558
      }
3552 3559
    }
3553 3560

	
3554 3561
    virtual void clear() {
3555 3562
      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
3556 3563
        _deg[it] = 0;
3557 3564
      }
3558 3565
    }
3559 3566
  private:
3560 3567

	
3561 3568
    const Digraph& _digraph;
3562 3569
    AutoNodeMap _deg;
3563 3570
  };
3564 3571

	
3565 3572
  /// \brief Map of the out-degrees of nodes in a digraph.
3566 3573
  ///
3567 3574
  /// This map returns the out-degree of a node. Once it is constructed,
3568 3575
  /// the degrees are stored in a standard \c NodeMap, so each query is done
3569 3576
  /// in constant time. On the other hand, the values are updated automatically
3570 3577
  /// whenever the digraph changes.
3571 3578
  ///
3572 3579
  /// \warning Besides \c addNode() and \c addArc(), a digraph structure
3573 3580
  /// may provide alternative ways to modify the digraph.
3574 3581
  /// The correct behavior of OutDegMap is not guarantied if these additional
3575 3582
  /// features are used. For example the functions
3576 3583
  /// \ref ListDigraph::changeSource() "changeSource()",
3577 3584
  /// \ref ListDigraph::changeTarget() "changeTarget()" and
3578 3585
  /// \ref ListDigraph::reverseArc() "reverseArc()"
3579 3586
  /// of \ref ListDigraph will \e not update the degree values correctly.
3580 3587
  ///
3581 3588
  /// \sa InDegMap
3582 3589
  template <typename GR>
3583 3590
  class OutDegMap
3584 3591
    : protected ItemSetTraits<GR, typename GR::Arc>
3585 3592
      ::ItemNotifier::ObserverBase {
3586 3593

	
3587 3594
  public:
3588 3595

	
3589 3596
    /// The graph type of OutDegMap
3590 3597
    typedef GR Graph;
3591 3598
    typedef GR Digraph;
3592 3599
    /// The key type
3593 3600
    typedef typename Digraph::Node Key;
3594 3601
    /// The value type
3595 3602
    typedef int Value;
3596 3603

	
3597 3604
    typedef typename ItemSetTraits<Digraph, typename Digraph::Arc>
3598 3605
    ::ItemNotifier::ObserverBase Parent;
3599 3606

	
3600 3607
  private:
3601 3608

	
3602 3609
    class AutoNodeMap
3603 3610
      : public ItemSetTraits<Digraph, Key>::template Map<int>::Type {
3604 3611
    public:
3605 3612

	
3606 3613
      typedef typename ItemSetTraits<Digraph, Key>::
3607 3614
      template Map<int>::Type Parent;
3608 3615

	
3609 3616
      AutoNodeMap(const Digraph& digraph) : Parent(digraph, 0) {}
3610 3617

	
3611 3618
      virtual void add(const Key& key) {
3612 3619
        Parent::add(key);
3613 3620
        Parent::set(key, 0);
3614 3621
      }
3615 3622
      virtual void add(const std::vector<Key>& keys) {
3616 3623
        Parent::add(keys);
3617 3624
        for (int i = 0; i < int(keys.size()); ++i) {
3618 3625
          Parent::set(keys[i], 0);
3619 3626
        }
3620 3627
      }
3621 3628
      virtual void build() {
3622 3629
        Parent::build();
3623 3630
        Key it;
3624 3631
        typename Parent::Notifier* nf = Parent::notifier();
3625 3632
        for (nf->first(it); it != INVALID; nf->next(it)) {
3626 3633
          Parent::set(it, 0);
3627 3634
        }
3628 3635
      }
3629 3636
    };
3630 3637

	
3631 3638
  public:
3632 3639

	
3633 3640
    /// \brief Constructor.
3634 3641
    ///
3635 3642
    /// Constructor for creating an out-degree map.
3636 3643
    explicit OutDegMap(const Digraph& graph)
3637 3644
      : _digraph(graph), _deg(graph) {
3638 3645
      Parent::attach(_digraph.notifier(typename Digraph::Arc()));
3639 3646

	
3640 3647
      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
3641 3648
        _deg[it] = countOutArcs(_digraph, it);
3642 3649
      }
3643 3650
    }
3644 3651

	
3645 3652
    /// \brief Gives back the out-degree of a Node.
3646 3653
    ///
3647 3654
    /// Gives back the out-degree of a Node.
3648 3655
    int operator[](const Key& key) const {
3649 3656
      return _deg[key];
3650 3657
    }
3651 3658

	
3652 3659
  protected:
3653 3660

	
3654 3661
    typedef typename Digraph::Arc Arc;
3655 3662

	
3656 3663
    virtual void add(const Arc& arc) {
3657 3664
      ++_deg[_digraph.source(arc)];
3658 3665
    }
3659 3666

	
3660 3667
    virtual void add(const std::vector<Arc>& arcs) {
3661 3668
      for (int i = 0; i < int(arcs.size()); ++i) {
3662 3669
        ++_deg[_digraph.source(arcs[i])];
3663 3670
      }
3664 3671
    }
3665 3672

	
3666 3673
    virtual void erase(const Arc& arc) {
3667 3674
      --_deg[_digraph.source(arc)];
3668 3675
    }
3669 3676

	
3670 3677
    virtual void erase(const std::vector<Arc>& arcs) {
3671 3678
      for (int i = 0; i < int(arcs.size()); ++i) {
3672 3679
        --_deg[_digraph.source(arcs[i])];
3673 3680
      }
3674 3681
    }
3675 3682

	
3676 3683
    virtual void build() {
3677 3684
      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
3678 3685
        _deg[it] = countOutArcs(_digraph, it);
3679 3686
      }
3680 3687
    }
3681 3688

	
3682 3689
    virtual void clear() {
3683 3690
      for(typename Digraph::NodeIt it(_digraph); it != INVALID; ++it) {
3684 3691
        _deg[it] = 0;
3685 3692
      }
3686 3693
    }
3687 3694
  private:
3688 3695

	
3689 3696
    const Digraph& _digraph;
3690 3697
    AutoNodeMap _deg;
3691 3698
  };
3692 3699

	
3693 3700
  /// \brief Potential difference map
3694 3701
  ///
3695 3702
  /// PotentialDifferenceMap returns the difference between the potentials of
3696 3703
  /// the source and target nodes of each arc in a digraph, i.e. it returns
3697 3704
  /// \code
3698 3705
  ///   potential[gr.target(arc)] - potential[gr.source(arc)].
3699 3706
  /// \endcode
3700 3707
  /// \tparam GR The digraph type.
3701 3708
  /// \tparam POT A node map storing the potentials.
3702 3709
  template <typename GR, typename POT>
3703 3710
  class PotentialDifferenceMap {
3704 3711
  public:
3705 3712
    /// Key type
3706 3713
    typedef typename GR::Arc Key;
3707 3714
    /// Value type
3708 3715
    typedef typename POT::Value Value;
3709 3716

	
3710 3717
    /// \brief Constructor
3711 3718
    ///
3712 3719
    /// Contructor of the map.
3713 3720
    explicit PotentialDifferenceMap(const GR& gr,
3714 3721
                                    const POT& potential)
3715 3722
      : _digraph(gr), _potential(potential) {}
3716 3723

	
3717 3724
    /// \brief Returns the potential difference for the given arc.
3718 3725
    ///
3719 3726
    /// Returns the potential difference for the given arc, i.e.
3720 3727
    /// \code
3721 3728
    ///   potential[gr.target(arc)] - potential[gr.source(arc)].
3722 3729
    /// \endcode
3723 3730
    Value operator[](const Key& arc) const {
3724 3731
      return _potential[_digraph.target(arc)] -
3725 3732
        _potential[_digraph.source(arc)];
3726 3733
    }
3727 3734

	
3728 3735
  private:
3729 3736
    const GR& _digraph;
3730 3737
    const POT& _potential;
3731 3738
  };
3732 3739

	
3733 3740
  /// \brief Returns a PotentialDifferenceMap.
3734 3741
  ///
3735 3742
  /// This function just returns a PotentialDifferenceMap.
3736 3743
  /// \relates PotentialDifferenceMap
3737 3744
  template <typename GR, typename POT>
3738 3745
  PotentialDifferenceMap<GR, POT>
3739 3746
  potentialDifferenceMap(const GR& gr, const POT& potential) {
3740 3747
    return PotentialDifferenceMap<GR, POT>(gr, potential);
3741 3748
  }
3742 3749

	
3743 3750
  /// @}
3744 3751
}
3745 3752

	
3746 3753
#endif // LEMON_MAPS_H
Ignore white space 2048 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5 5
 * Copyright (C) 2003-2009
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#include <deque>
20 20
#include <set>
21 21

	
22 22
#include <lemon/concept_check.h>
23 23
#include <lemon/concepts/maps.h>
24 24
#include <lemon/maps.h>
25 25
#include <lemon/list_graph.h>
26 26
#include <lemon/smart_graph.h>
27 27
#include <lemon/adaptors.h>
28 28
#include <lemon/dfs.h>
29 29

	
30 30
#include "test_tools.h"
31 31

	
32 32
using namespace lemon;
33 33
using namespace lemon::concepts;
34 34

	
35 35
struct A {};
36 36
inline bool operator<(A, A) { return true; }
37 37
struct B {};
38 38

	
39 39
class C {
40 40
  int x;
41 41
public:
42 42
  C(int _x) : x(_x) {}
43 43
};
44 44

	
45 45
class F {
46 46
public:
47 47
  typedef A argument_type;
48 48
  typedef B result_type;
49 49

	
50 50
  B operator()(const A&) const { return B(); }
51 51
private:
52 52
  F& operator=(const F&);
53 53
};
54 54

	
55 55
int func(A) { return 3; }
56 56

	
57 57
int binc(int a, B) { return a+1; }
58 58

	
59 59
typedef ReadMap<A, double> DoubleMap;
60 60
typedef ReadWriteMap<A, double> DoubleWriteMap;
61 61
typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap;
62 62

	
63 63
typedef ReadMap<A, bool> BoolMap;
64 64
typedef ReadWriteMap<A, bool> BoolWriteMap;
65 65
typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap;
66 66

	
67 67
template<typename Map1, typename Map2, typename ItemIt>
68 68
void compareMap(const Map1& map1, const Map2& map2, ItemIt it) {
69 69
  for (; it != INVALID; ++it)
70 70
    check(map1[it] == map2[it], "The maps are not equal");
71 71
}
72 72

	
73 73
int main()
74 74
{
75 75
  // Map concepts
76 76
  checkConcept<ReadMap<A,B>, ReadMap<A,B> >();
77 77
  checkConcept<ReadMap<A,C>, ReadMap<A,C> >();
78 78
  checkConcept<WriteMap<A,B>, WriteMap<A,B> >();
79 79
  checkConcept<WriteMap<A,C>, WriteMap<A,C> >();
80 80
  checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >();
81 81
  checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >();
82 82
  checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
83 83
  checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
84 84

	
85 85
  // NullMap
86 86
  {
87 87
    checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
88 88
    NullMap<A,B> map1;
89 89
    NullMap<A,B> map2 = map1;
90 90
    map1 = nullMap<A,B>();
91 91
  }
92 92

	
93 93
  // ConstMap
94 94
  {
95 95
    checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
96 96
    checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
97 97
    ConstMap<A,B> map1;
98 98
    ConstMap<A,B> map2 = B();
99 99
    ConstMap<A,B> map3 = map1;
100 100
    map1 = constMap<A>(B());
101 101
    map1 = constMap<A,B>();
102 102
    map1.setAll(B());
103 103
    ConstMap<A,C> map4(C(1));
104 104
    ConstMap<A,C> map5 = map4;
105 105
    map4 = constMap<A>(C(2));
106 106
    map4.setAll(C(3));
107 107

	
108 108
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
109 109
    check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
110 110

	
111 111
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
112 112
    ConstMap<A,Const<int,10> > map6;
113 113
    ConstMap<A,Const<int,10> > map7 = map6;
114 114
    map6 = constMap<A,int,10>();
115 115
    map7 = constMap<A,Const<int,10> >();
116 116
    check(map6[A()] == 10 && map7[A()] == 10,
117 117
          "Something is wrong with ConstMap");
118 118
  }
119 119

	
120 120
  // IdentityMap
121 121
  {
122 122
    checkConcept<ReadMap<A,A>, IdentityMap<A> >();
123 123
    IdentityMap<A> map1;
124 124
    IdentityMap<A> map2 = map1;
125 125
    map1 = identityMap<A>();
126 126

	
127 127
    checkConcept<ReadMap<double,double>, IdentityMap<double> >();
128 128
    check(identityMap<double>()[1.0] == 1.0 &&
129 129
          identityMap<double>()[3.14] == 3.14,
130 130
          "Something is wrong with IdentityMap");
131 131
  }
132 132

	
133 133
  // RangeMap
134 134
  {
135 135
    checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >();
136 136
    RangeMap<B> map1;
137 137
    RangeMap<B> map2(10);
138 138
    RangeMap<B> map3(10,B());
139 139
    RangeMap<B> map4 = map1;
140 140
    RangeMap<B> map5 = rangeMap<B>();
141 141
    RangeMap<B> map6 = rangeMap<B>(10);
142 142
    RangeMap<B> map7 = rangeMap(10,B());
143 143

	
144 144
    checkConcept< ReferenceMap<int, double, double&, const double&>,
145 145
                  RangeMap<double> >();
146 146
    std::vector<double> v(10, 0);
147 147
    v[5] = 100;
148 148
    RangeMap<double> map8(v);
149 149
    RangeMap<double> map9 = rangeMap(v);
150 150
    check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100,
151 151
          "Something is wrong with RangeMap");
152 152
  }
153 153

	
154 154
  // SparseMap
155 155
  {
156 156
    checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >();
157 157
    SparseMap<A,B> map1;
158 158
    SparseMap<A,B> map2 = B();
159 159
    SparseMap<A,B> map3 = sparseMap<A,B>();
160 160
    SparseMap<A,B> map4 = sparseMap<A>(B());
161 161

	
162 162
    checkConcept< ReferenceMap<double, int, int&, const int&>,
163 163
                  SparseMap<double, int> >();
164 164
    std::map<double, int> m;
165 165
    SparseMap<double, int> map5(m);
166 166
    SparseMap<double, int> map6(m,10);
167 167
    SparseMap<double, int> map7 = sparseMap(m);
168 168
    SparseMap<double, int> map8 = sparseMap(m,10);
169 169

	
170 170
    check(map5[1.0] == 0 && map5[3.14] == 0 &&
171 171
          map6[1.0] == 10 && map6[3.14] == 10,
172 172
          "Something is wrong with SparseMap");
173 173
    map5[1.0] = map6[3.14] = 100;
174 174
    check(map5[1.0] == 100 && map5[3.14] == 0 &&
175 175
          map6[1.0] == 10 && map6[3.14] == 100,
176 176
          "Something is wrong with SparseMap");
177 177
  }
178 178

	
179 179
  // ComposeMap
180 180
  {
181 181
    typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
182 182
    checkConcept<ReadMap<B,double>, CompMap>();
183 183
    CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
184 184
    CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
185 185

	
186 186
    SparseMap<double, bool> m1(false); m1[3.14] = true;
187 187
    RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
188 188
    check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
189 189
          "Something is wrong with ComposeMap")
190 190
  }
191 191

	
192 192
  // CombineMap
193 193
  {
194 194
    typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
195 195
    checkConcept<ReadMap<A,double>, CombMap>();
196 196
    CombMap map1 = CombMap(DoubleMap(), DoubleMap());
197 197
    CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
198 198

	
199 199
    check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
200 200
          "Something is wrong with CombineMap");
201 201
  }
202 202

	
203 203
  // FunctorToMap, MapToFunctor
204 204
  {
205 205
    checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
206 206
    checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
207 207
    FunctorToMap<F> map1;
208 208
    FunctorToMap<F> map2 = FunctorToMap<F>(F());
209 209
    B b = functorToMap(F())[A()];
210 210

	
211 211
    checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
212 212
    MapToFunctor<ReadMap<A,B> > map = MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
213 213

	
214 214
    check(functorToMap(&func)[A()] == 3,
215 215
          "Something is wrong with FunctorToMap");
216 216
    check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
217 217
          "Something is wrong with MapToFunctor");
218 218
    check(mapToFunctor(functorToMap(&func))(A()) == 3 &&
219 219
          mapToFunctor(functorToMap(&func))[A()] == 3,
220 220
          "Something is wrong with FunctorToMap or MapToFunctor");
221 221
    check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2,
222 222
          "Something is wrong with FunctorToMap or MapToFunctor");
223 223
  }
224 224

	
225 225
  // ConvertMap
226 226
  {
227 227
    checkConcept<ReadMap<double,double>,
228 228
      ConvertMap<ReadMap<double, int>, double> >();
229 229
    ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
230 230
    ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
231 231
  }
232 232

	
233 233
  // ForkMap
234 234
  {
235 235
    checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
236 236

	
237 237
    typedef RangeMap<double> RM;
238 238
    typedef SparseMap<int, double> SM;
239 239
    RM m1(10, -1);
240 240
    SM m2(-1);
241 241
    checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >();
242 242
    checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >();
243 243
    ForkMap<RM, SM> map1(m1,m2);
244 244
    ForkMap<SM, RM> map2 = forkMap(m2,m1);
245 245
    map2.set(5, 10);
246 246
    check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 &&
247 247
          m2[5] == 10 && map2[1] == -1 && map2[5] == 10,
248 248
          "Something is wrong with ForkMap");
249 249
  }
250 250

	
251 251
  // Arithmetic maps:
252 252
  // - AddMap, SubMap, MulMap, DivMap
253 253
  // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap
254 254
  // - NegMap, NegWriteMap, AbsMap
255 255
  {
256 256
    checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >();
257 257
    checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >();
258 258
    checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >();
259 259
    checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >();
260 260

	
261 261
    ConstMap<int, double> c1(1.0), c2(3.14);
262 262
    IdentityMap<int> im;
263 263
    ConvertMap<IdentityMap<int>, double> id(im);
264 264
    check(addMap(c1,id)[0] == 1.0  && addMap(c1,id)[10] == 11.0,
265 265
          "Something is wrong with AddMap");
266 266
    check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0,
267 267
          "Something is wrong with SubMap");
268 268
    check(mulMap(id,c2)[0] == 0    && mulMap(id,c2)[2]  == 6.28,
269 269
          "Something is wrong with MulMap");
270 270
    check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2]  == 1.57,
271 271
          "Something is wrong with DivMap");
272 272

	
273 273
    checkConcept<DoubleMap, ShiftMap<DoubleMap> >();
274 274
    checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >();
275 275
    checkConcept<DoubleMap, ScaleMap<DoubleMap> >();
276 276
    checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >();
277 277
    checkConcept<DoubleMap, NegMap<DoubleMap> >();
278 278
    checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >();
279 279
    checkConcept<DoubleMap, AbsMap<DoubleMap> >();
280 280

	
281 281
    check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0,
282 282
          "Something is wrong with ShiftMap");
283 283
    check(shiftWriteMap(id, 2.0)[1] == 3.0 &&
284 284
          shiftWriteMap(id, 2.0)[10] == 12.0,
285 285
          "Something is wrong with ShiftWriteMap");
286 286
    check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0,
287 287
          "Something is wrong with ScaleMap");
288 288
    check(scaleWriteMap(id, 2.0)[1] == 2.0 &&
289 289
          scaleWriteMap(id, 2.0)[10] == 20.0,
290 290
          "Something is wrong with ScaleWriteMap");
291 291
    check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0,
292 292
          "Something is wrong with NegMap");
293 293
    check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0,
294 294
          "Something is wrong with NegWriteMap");
295 295
    check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0,
296 296
          "Something is wrong with AbsMap");
297 297
  }
298 298

	
299 299
  // Logical maps:
300 300
  // - TrueMap, FalseMap
301 301
  // - AndMap, OrMap
302 302
  // - NotMap, NotWriteMap
303 303
  // - EqualMap, LessMap
304 304
  {
305 305
    checkConcept<BoolMap, TrueMap<A> >();
306 306
    checkConcept<BoolMap, FalseMap<A> >();
307 307
    checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >();
308 308
    checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >();
309 309
    checkConcept<BoolMap, NotMap<BoolMap> >();
310 310
    checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >();
311 311
    checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >();
312 312
    checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >();
313 313

	
314 314
    TrueMap<int> tm;
315 315
    FalseMap<int> fm;
316 316
    RangeMap<bool> rm(2);
317 317
    rm[0] = true; rm[1] = false;
318 318
    check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] &&
319 319
          !andMap(fm,rm)[0] && !andMap(fm,rm)[1],
320 320
          "Something is wrong with AndMap");
321 321
    check(orMap(tm,rm)[0] && orMap(tm,rm)[1] &&
322 322
          orMap(fm,rm)[0] && !orMap(fm,rm)[1],
323 323
          "Something is wrong with OrMap");
324 324
    check(!notMap(rm)[0] && notMap(rm)[1],
325 325
          "Something is wrong with NotMap");
326 326
    check(!notWriteMap(rm)[0] && notWriteMap(rm)[1],
327 327
          "Something is wrong with NotWriteMap");
328 328

	
329 329
    ConstMap<int, double> cm(2.0);
330 330
    IdentityMap<int> im;
331 331
    ConvertMap<IdentityMap<int>, double> id(im);
332 332
    check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3],
333 333
          "Something is wrong with LessMap");
334 334
    check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3],
335 335
          "Something is wrong with EqualMap");
336 336
  }
337 337

	
338 338
  // LoggerBoolMap
339 339
  {
340 340
    typedef std::vector<int> vec;
341 341
    checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >();
342 342
    checkConcept<WriteMap<int, bool>,
343 343
                 LoggerBoolMap<std::back_insert_iterator<vec> > >();
344 344

	
345 345
    vec v1;
346 346
    vec v2(10);
347 347
    LoggerBoolMap<std::back_insert_iterator<vec> >
348 348
      map1(std::back_inserter(v1));
349 349
    LoggerBoolMap<vec::iterator> map2(v2.begin());
350 350
    map1.set(10, false);
351 351
    map1.set(20, true);   map2.set(20, true);
352 352
    map1.set(30, false);  map2.set(40, false);
353 353
    map1.set(50, true);   map2.set(50, true);
354 354
    map1.set(60, true);   map2.set(60, true);
355 355
    check(v1.size() == 3 && v2.size() == 10 &&
356 356
          v1[0]==20 && v1[1]==50 && v1[2]==60 &&
357 357
          v2[0]==20 && v2[1]==50 && v2[2]==60,
358 358
          "Something is wrong with LoggerBoolMap");
359 359

	
360 360
    int i = 0;
361 361
    for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin();
362 362
          it != map2.end(); ++it )
363 363
      check(v1[i++] == *it, "Something is wrong with LoggerBoolMap");
364 364
    
365 365
    typedef ListDigraph Graph;
366 366
    DIGRAPH_TYPEDEFS(Graph);
367 367
    Graph gr;
368 368

	
369 369
    Node n0 = gr.addNode();
370 370
    Node n1 = gr.addNode();
371 371
    Node n2 = gr.addNode();
372 372
    Node n3 = gr.addNode();
373 373
    
374 374
    gr.addArc(n3, n0);
375 375
    gr.addArc(n3, n2);
376 376
    gr.addArc(n0, n2);
377 377
    gr.addArc(n2, n1);
378 378
    gr.addArc(n0, n1);
379 379
    
380 380
    {
381 381
      std::vector<Node> v;
382 382
      dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run();
383 383

	
384 384
      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
385 385
            "Something is wrong with LoggerBoolMap");
386 386
    }
387 387
    {
388 388
      std::vector<Node> v(countNodes(gr));
389 389
      dfs(gr).processedMap(loggerBoolMap(v.begin())).run();
390 390
      
391 391
      check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3,
392 392
            "Something is wrong with LoggerBoolMap");
393 393
    }
394 394
  }
395 395
  
396 396
  // IdMap, RangeIdMap
397 397
  {
398 398
    typedef ListDigraph Graph;
399 399
    DIGRAPH_TYPEDEFS(Graph);
400 400

	
401 401
    checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >();
402 402
    checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >();
403 403
    checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >();
404 404
    checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >();
405 405
    
406 406
    Graph gr;
407 407
    IdMap<Graph, Node> nmap(gr);
408 408
    IdMap<Graph, Arc> amap(gr);
409 409
    RangeIdMap<Graph, Node> nrmap(gr);
410 410
    RangeIdMap<Graph, Arc> armap(gr);
411 411
    
412 412
    Node n0 = gr.addNode();
413 413
    Node n1 = gr.addNode();
414 414
    Node n2 = gr.addNode();
415 415
    
416 416
    Arc a0 = gr.addArc(n0, n1);
417 417
    Arc a1 = gr.addArc(n0, n2);
418 418
    Arc a2 = gr.addArc(n2, n1);
419 419
    Arc a3 = gr.addArc(n2, n0);
420 420
    
421 421
    check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap");
422 422
    check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap");
423 423
    check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap");
424 424

	
425 425
    check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap");
426 426
    check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap");
427 427
    check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap");
428 428
    check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap");
429 429

	
430 430
    check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap");
431 431
    check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap");
432 432
    
433 433
    check(nrmap.size() == 3 && armap.size() == 4,
434 434
          "Wrong RangeIdMap::size()");
435 435

	
436 436
    check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap");
437 437
    check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap");
438 438
    check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap");
439 439
    
440 440
    check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap");
441 441
    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
442 442
    check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap");
443 443
    check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap");
444 444

	
445 445
    check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap");
446 446
    check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap");
447 447
    
448 448
    gr.erase(n1);
449 449
    
450 450
    if (nrmap[n0] == 1) nrmap.swap(n0, n2);
451 451
    nrmap.swap(n2, n0);
452 452
    if (armap[a1] == 1) armap.swap(a1, a3);
453 453
    armap.swap(a3, a1);
454 454
    
455 455
    check(nrmap.size() == 2 && armap.size() == 2,
456 456
          "Wrong RangeIdMap::size()");
457 457

	
458 458
    check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap");
459 459
    check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap");
460 460
    
461 461
    check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap");
462 462
    check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap");
463 463

	
464 464
    check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap");
465 465
    check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap");
466 466
  }
467 467
  
468 468
  // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap
469 469
  {
470 470
    typedef ListGraph Graph;
471 471
    GRAPH_TYPEDEFS(Graph);
472 472
    
473 473
    checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >();
474 474
    checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >();
475 475
    checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >();
476 476
    checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >();
477 477
    checkConcept<ReadMap<Node, int>, InDegMap<Graph> >();
478 478
    checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >();
479 479

	
480 480
    Graph gr;
481 481
    Node n0 = gr.addNode();
482 482
    Node n1 = gr.addNode();
483 483
    Node n2 = gr.addNode();
484 484
    
485 485
    gr.addEdge(n0,n1);
486 486
    gr.addEdge(n1,n2);
487 487
    gr.addEdge(n0,n2);
488 488
    gr.addEdge(n2,n1);
489 489
    gr.addEdge(n1,n2);
490 490
    gr.addEdge(n0,n1);
491 491
    
492 492
    for (EdgeIt e(gr); e != INVALID; ++e) {
493 493
      check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap");
494 494
      check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap");
495 495
    }
496 496
    
497 497
    compareMap(sourceMap(orienter(gr, constMap<Edge, bool>(true))),
498 498
               targetMap(orienter(gr, constMap<Edge, bool>(false))),
499 499
               EdgeIt(gr));
500 500

	
501 501
    typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph;
502 502
    Digraph dgr(gr, constMap<Edge, bool>(true));
503 503
    OutDegMap<Digraph> odm(dgr);
504 504
    InDegMap<Digraph> idm(dgr);
505 505
    
506 506
    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap");
507 507
    check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
508 508
   
509 509
    gr.addEdge(n2, n0);
510 510

	
511 511
    check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap");
512 512
    check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap");
513 513
  }
514 514
  
515 515
  // CrossRefMap
516 516
  {
517 517
    typedef ListDigraph Graph;
518 518
    DIGRAPH_TYPEDEFS(Graph);
519 519

	
520 520
    checkConcept<ReadWriteMap<Node, int>,
521 521
                 CrossRefMap<Graph, Node, int> >();
522 522
    checkConcept<ReadWriteMap<Node, bool>,
523 523
                 CrossRefMap<Graph, Node, bool> >();
524 524
    checkConcept<ReadWriteMap<Node, double>,
525 525
                 CrossRefMap<Graph, Node, double> >();
526 526
    
527 527
    Graph gr;
528 528
    typedef CrossRefMap<Graph, Node, char> CRMap;
529
    typedef CRMap::ValueIterator ValueIt;
530 529
    CRMap map(gr);
531 530
    
532 531
    Node n0 = gr.addNode();
533 532
    Node n1 = gr.addNode();
534 533
    Node n2 = gr.addNode();
535 534
    
536 535
    map.set(n0, 'A');
537 536
    map.set(n1, 'B');
538 537
    map.set(n2, 'C');
539 538
    
540 539
    check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
541 540
          "Wrong CrossRefMap");
542 541
    check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
543 542
          "Wrong CrossRefMap");
544 543
    check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
545 544
          "Wrong CrossRefMap");
546 545
    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
547 546
          "Wrong CrossRefMap::count()");
548 547
    
549
    ValueIt it = map.beginValue();
548
    CRMap::ValueIt it = map.beginValue();
550 549
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
551 550
          it == map.endValue(), "Wrong value iterator");
552 551
    
553 552
    map.set(n2, 'A');
554 553

	
555 554
    check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
556 555
          "Wrong CrossRefMap");
557 556
    check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
558 557
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
559 558
    check(map('C') == INVALID && map.inverse()['C'] == INVALID,
560 559
          "Wrong CrossRefMap");
561 560
    check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
562 561
          "Wrong CrossRefMap::count()");
563 562

	
564 563
    it = map.beginValue();
565 564
    check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
566 565
          it == map.endValue(), "Wrong value iterator");
567 566

	
568 567
    map.set(n0, 'C');
569 568

	
570 569
    check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
571 570
          "Wrong CrossRefMap");
572 571
    check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
573 572
    check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
574 573
    check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
575 574
    check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
576 575
          "Wrong CrossRefMap::count()");
577 576

	
578 577
    it = map.beginValue();
579 578
    check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
580 579
          it == map.endValue(), "Wrong value iterator");
581 580
  }
582 581

	
583 582
  // Iterable bool map
584 583
  {
585 584
    typedef SmartGraph Graph;
586 585
    typedef SmartGraph::Node Item;
587 586

	
588 587
    typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
589 588
    checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
590 589

	
591 590
    const int num = 10;
592 591
    Graph g;
593 592
    std::vector<Item> items;
594 593
    for (int i = 0; i < num; ++i) {
595 594
      items.push_back(g.addNode());
596 595
    }
597 596

	
598 597
    Ibm map1(g, true);
599 598
    int n = 0;
600 599
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
601 600
      check(map1[static_cast<Item>(it)], "Wrong TrueIt");
602 601
      ++n;
603 602
    }
604 603
    check(n == num, "Wrong number");
605 604

	
606 605
    n = 0;
607 606
    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
608 607
        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
609 608
        ++n;
610 609
    }
611 610
    check(n == num, "Wrong number");
612 611
    check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
613 612
    check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
614 613

	
615 614
    map1[items[5]] = true;
616 615

	
617 616
    n = 0;
618 617
    for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
619 618
        check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
620 619
        ++n;
621 620
    }
622 621
    check(n == num, "Wrong number");
623 622

	
624 623
    map1[items[num / 2]] = false;
625 624
    check(map1[items[num / 2]] == false, "Wrong map value");
626 625

	
627 626
    n = 0;
628 627
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
629 628
        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
630 629
        ++n;
631 630
    }
632 631
    check(n == num - 1, "Wrong number");
633 632

	
634 633
    n = 0;
635 634
    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
636 635
        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
637 636
        ++n;
638 637
    }
639 638
    check(n == 1, "Wrong number");
640 639

	
641 640
    map1[items[0]] = false;
642 641
    check(map1[items[0]] == false, "Wrong map value");
643 642

	
644 643
    map1[items[num - 1]] = false;
645 644
    check(map1[items[num - 1]] == false, "Wrong map value");
646 645

	
647 646
    n = 0;
648 647
    for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
649 648
        check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
650 649
        ++n;
651 650
    }
652 651
    check(n == num - 3, "Wrong number");
653 652
    check(map1.trueNum() == num - 3, "Wrong number");
654 653

	
655 654
    n = 0;
656 655
    for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
657 656
        check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
658 657
        ++n;
659 658
    }
660 659
    check(n == 3, "Wrong number");
661 660
    check(map1.falseNum() == 3, "Wrong number");
662 661
  }
663 662

	
664 663
  // Iterable int map
665 664
  {
666 665
    typedef SmartGraph Graph;
667 666
    typedef SmartGraph::Node Item;
668 667
    typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
669 668

	
670 669
    checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
671 670

	
672 671
    const int num = 10;
673 672
    Graph g;
674 673
    std::vector<Item> items;
675 674
    for (int i = 0; i < num; ++i) {
676 675
      items.push_back(g.addNode());
677 676
    }
678 677

	
679 678
    Iim map1(g);
680 679
    check(map1.size() == 0, "Wrong size");
681 680

	
682 681
    for (int i = 0; i < num; ++i) {
683 682
      map1[items[i]] = i;
684 683
    }
685 684
    check(map1.size() == num, "Wrong size");
686 685

	
687 686
    for (int i = 0; i < num; ++i) {
688 687
      Iim::ItemIt it(map1, i);
689 688
      check(static_cast<Item>(it) == items[i], "Wrong value");
690 689
      ++it;
691 690
      check(static_cast<Item>(it) == INVALID, "Wrong value");
692 691
    }
693 692

	
694 693
    for (int i = 0; i < num; ++i) {
695 694
      map1[items[i]] = i % 2;
696 695
    }
697 696
    check(map1.size() == 2, "Wrong size");
698 697

	
699 698
    int n = 0;
700 699
    for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
701 700
      check(map1[static_cast<Item>(it)] == 0, "Wrong value");
702 701
      ++n;
703 702
    }
704 703
    check(n == (num + 1) / 2, "Wrong number");
705 704

	
706 705
    for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
707 706
      check(map1[static_cast<Item>(it)] == 1, "Wrong value");
708 707
      ++n;
709 708
    }
710 709
    check(n == num, "Wrong number");
711 710

	
712 711
  }
713 712

	
714 713
  // Iterable value map
715 714
  {
716 715
    typedef SmartGraph Graph;
717 716
    typedef SmartGraph::Node Item;
718 717
    typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
719 718

	
720 719
    checkConcept<ReadWriteMap<Item, double>, Ivm>();
721 720

	
722 721
    const int num = 10;
723 722
    Graph g;
724 723
    std::vector<Item> items;
725 724
    for (int i = 0; i < num; ++i) {
726 725
      items.push_back(g.addNode());
727 726
    }
728 727

	
729 728
    Ivm map1(g, 0.0);
730 729
    check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
731 730
    check(*map1.beginValue() == 0.0, "Wrong value");
732 731

	
733 732
    for (int i = 0; i < num; ++i) {
734 733
      map1.set(items[i], static_cast<double>(i));
735 734
    }
736 735
    check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
737 736

	
738 737
    for (int i = 0; i < num; ++i) {
739 738
      Ivm::ItemIt it(map1, static_cast<double>(i));
740 739
      check(static_cast<Item>(it) == items[i], "Wrong value");
741 740
      ++it;
742 741
      check(static_cast<Item>(it) == INVALID, "Wrong value");
743 742
    }
744 743

	
745
    for (Ivm::ValueIterator vit = map1.beginValue();
744
    for (Ivm::ValueIt vit = map1.beginValue();
746 745
         vit != map1.endValue(); ++vit) {
747 746
      check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
748
            "Wrong ValueIterator");
747
            "Wrong ValueIt");
749 748
    }
750 749

	
751 750
    for (int i = 0; i < num; ++i) {
752 751
      map1.set(items[i], static_cast<double>(i % 2));
753 752
    }
754 753
    check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
755 754

	
756 755
    int n = 0;
757 756
    for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
758 757
      check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
759 758
      ++n;
760 759
    }
761 760
    check(n == (num + 1) / 2, "Wrong number");
762 761

	
763 762
    for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
764 763
      check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
765 764
      ++n;
766 765
    }
767 766
    check(n == num, "Wrong number");
768 767

	
769 768
  }
770 769
  return 0;
771 770
}
0 comments (0 inline)