gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Bug fix in maps.h.
0 1 0
default
1 file changed with 2 insertions and 2 deletions:
↑ Collapse diff ↑
Ignore white space 192 line context
... ...
@@ -1215,228 +1215,228 @@
1215 1215

	
1216 1216
  }
1217 1217
  
1218 1218

	
1219 1219
  /// \brief Writable bool map for logging each \c true assigned element
1220 1220
  ///
1221 1221
  /// Writable bool map for logging each \c true assigned element, i.e it
1222 1222
  /// copies all the keys set to \c true to the given iterator.
1223 1223
  ///
1224 1224
  /// \note The container of the iterator should contain space 
1225 1225
  /// for each element.
1226 1226
  ///
1227 1227
  /// The following example shows how you can write the edges found by the Prim
1228 1228
  /// algorithm directly
1229 1229
  /// to the standard output.
1230 1230
  ///\code
1231 1231
  /// typedef IdMap<Graph, Edge> EdgeIdMap;
1232 1232
  /// EdgeIdMap edgeId(graph);
1233 1233
  ///
1234 1234
  /// typedef MapFunctor<EdgeIdMap> EdgeIdFunctor;
1235 1235
  /// EdgeIdFunctor edgeIdFunctor(edgeId);
1236 1236
  ///
1237 1237
  /// StoreBoolMap<ostream_iterator<int>, EdgeIdFunctor> 
1238 1238
  ///   writerMap(ostream_iterator<int>(cout, " "), edgeIdFunctor);
1239 1239
  ///
1240 1240
  /// prim(graph, cost, writerMap);
1241 1241
  ///\endcode
1242 1242
  ///
1243 1243
  ///\sa BackInserterBoolMap 
1244 1244
  ///\sa FrontInserterBoolMap 
1245 1245
  ///\sa InserterBoolMap 
1246 1246
  ///
1247 1247
  ///\todo Revise the name of this class and the related ones.
1248 1248
  template <typename _Iterator, 
1249 1249
            typename _Functor =
1250 1250
            _maps_bits::Identity<typename _maps_bits::
1251 1251
                                 IteratorTraits<_Iterator>::Value> >
1252 1252
  class StoreBoolMap {
1253 1253
  public:
1254 1254
    typedef _Iterator Iterator;
1255 1255

	
1256 1256
    typedef typename _Functor::argument_type Key;
1257 1257
    typedef bool Value;
1258 1258

	
1259 1259
    typedef _Functor Functor;
1260 1260

	
1261 1261
    /// Constructor
1262 1262
    StoreBoolMap(Iterator it, const Functor& functor = Functor()) 
1263 1263
      : _begin(it), _end(it), _functor(functor) {}
1264 1264

	
1265 1265
    /// Gives back the given iterator set for the first key
1266 1266
    Iterator begin() const {
1267 1267
      return _begin;
1268 1268
    }
1269 1269
 
1270 1270
    /// Gives back the the 'after the last' iterator
1271 1271
    Iterator end() const {
1272 1272
      return _end;
1273 1273
    }
1274 1274

	
1275 1275
    /// The \c set function of the map
1276 1276
    void set(const Key& key, Value value) const {
1277 1277
      if (value) {
1278 1278
	*_end++ = _functor(key);
1279 1279
      }
1280 1280
    }
1281 1281
    
1282 1282
  private:
1283 1283
    Iterator _begin;
1284 1284
    mutable Iterator _end;
1285 1285
    Functor _functor;
1286 1286
  };
1287 1287

	
1288 1288
  /// \brief Writable bool map for logging each \c true assigned element in 
1289 1289
  /// a back insertable container.
1290 1290
  ///
1291 1291
  /// Writable bool map for logging each \c true assigned element by pushing
1292 1292
  /// them into a back insertable container.
1293 1293
  /// It can be used to retrieve the items into a standard
1294 1294
  /// container. The next example shows how you can store the
1295 1295
  /// edges found by the Prim algorithm in a vector.
1296 1296
  ///
1297 1297
  ///\code
1298 1298
  /// vector<Edge> span_tree_edges;
1299 1299
  /// BackInserterBoolMap<vector<Edge> > inserter_map(span_tree_edges);
1300 1300
  /// prim(graph, cost, inserter_map);
1301 1301
  ///\endcode
1302 1302
  ///
1303 1303
  ///\sa StoreBoolMap
1304 1304
  ///\sa FrontInserterBoolMap
1305 1305
  ///\sa InserterBoolMap
1306 1306
  template <typename Container,
1307 1307
            typename Functor =
1308 1308
            _maps_bits::Identity<typename Container::value_type> >
1309 1309
  class BackInserterBoolMap {
1310 1310
  public:
1311
    typedef typename Container::value_type Key;
1311
    typedef typename Functor::argument_type Key;
1312 1312
    typedef bool Value;
1313 1313

	
1314 1314
    /// Constructor
1315 1315
    BackInserterBoolMap(Container& _container, 
1316 1316
                        const Functor& _functor = Functor()) 
1317 1317
      : container(_container), functor(_functor) {}
1318 1318

	
1319 1319
    /// The \c set function of the map
1320 1320
    void set(const Key& key, Value value) {
1321 1321
      if (value) {
1322 1322
	container.push_back(functor(key));
1323 1323
      }
1324 1324
    }
1325 1325
    
1326 1326
  private:
1327 1327
    Container& container;
1328 1328
    Functor functor;
1329 1329
  };
1330 1330

	
1331 1331
  /// \brief Writable bool map for logging each \c true assigned element in 
1332 1332
  /// a front insertable container.
1333 1333
  ///
1334 1334
  /// Writable bool map for logging each \c true assigned element by pushing
1335 1335
  /// them into a front insertable container.
1336 1336
  /// It can be used to retrieve the items into a standard
1337 1337
  /// container. For example see \ref BackInserterBoolMap.
1338 1338
  ///
1339 1339
  ///\sa BackInserterBoolMap
1340 1340
  ///\sa InserterBoolMap
1341 1341
  template <typename Container,
1342 1342
            typename Functor =
1343 1343
            _maps_bits::Identity<typename Container::value_type> >
1344 1344
  class FrontInserterBoolMap {
1345 1345
  public:
1346
    typedef typename Container::value_type Key;
1346
    typedef typename Functor::argument_type Key;
1347 1347
    typedef bool Value;
1348 1348

	
1349 1349
    /// Constructor
1350 1350
    FrontInserterBoolMap(Container& _container,
1351 1351
                         const Functor& _functor = Functor()) 
1352 1352
      : container(_container), functor(_functor) {}
1353 1353

	
1354 1354
    /// The \c set function of the map
1355 1355
    void set(const Key& key, Value value) {
1356 1356
      if (value) {
1357 1357
	container.push_front(functor(key));
1358 1358
      }
1359 1359
    }
1360 1360
    
1361 1361
  private:
1362 1362
    Container& container;    
1363 1363
    Functor functor;
1364 1364
  };
1365 1365

	
1366 1366
  /// \brief Writable bool map for storing each \c true assigned element in 
1367 1367
  /// an insertable container.
1368 1368
  ///
1369 1369
  /// Writable bool map for storing each \c true assigned element in an 
1370 1370
  /// insertable container. It will insert all the keys set to \c true into
1371 1371
  /// the container.
1372 1372
  ///
1373 1373
  /// For example, if you want to store the cut arcs of the strongly
1374 1374
  /// connected components in a set you can use the next code:
1375 1375
  ///
1376 1376
  ///\code
1377 1377
  /// set<Arc> cut_arcs;
1378 1378
  /// InserterBoolMap<set<Arc> > inserter_map(cut_arcs);
1379 1379
  /// stronglyConnectedCutArcs(digraph, cost, inserter_map);
1380 1380
  ///\endcode
1381 1381
  ///
1382 1382
  ///\sa BackInserterBoolMap
1383 1383
  ///\sa FrontInserterBoolMap
1384 1384
  template <typename Container,
1385 1385
            typename Functor =
1386 1386
            _maps_bits::Identity<typename Container::value_type> >
1387 1387
  class InserterBoolMap {
1388 1388
  public:
1389 1389
    typedef typename Container::value_type Key;
1390 1390
    typedef bool Value;
1391 1391

	
1392 1392
    /// Constructor with specified iterator
1393 1393
    
1394 1394
    /// Constructor with specified iterator.
1395 1395
    /// \param _container The container for storing the elements.
1396 1396
    /// \param _it The elements will be inserted before this iterator.
1397 1397
    /// \param _functor The functor that is used when an element is stored.
1398 1398
    InserterBoolMap(Container& _container, typename Container::iterator _it,
1399 1399
                    const Functor& _functor = Functor()) 
1400 1400
      : container(_container), it(_it), functor(_functor) {}
1401 1401

	
1402 1402
    /// Constructor
1403 1403

	
1404 1404
    /// Constructor without specified iterator.
1405 1405
    /// The elements will be inserted before <tt>_container.end()</tt>.
1406 1406
    /// \param _container The container for storing the elements.
1407 1407
    /// \param _functor The functor that is used when an element is stored.
1408 1408
    InserterBoolMap(Container& _container, const Functor& _functor = Functor())
1409 1409
      : container(_container), it(_container.end()), functor(_functor) {}
1410 1410

	
1411 1411
    /// The \c set function of the map
1412 1412
    void set(const Key& key, Value value) {
1413 1413
      if (value) {
1414 1414
	it = container.insert(it, functor(key));
1415 1415
        ++it;
1416 1416
      }
1417 1417
    }
1418 1418
    
1419 1419
  private:
1420 1420
    Container& container;
1421 1421
    typename Container::iterator it;
1422 1422
    Functor functor;
1423 1423
  };
1424 1424

	
1425 1425
  /// \brief Writable bool map for filling each \c true assigned element with a 
1426 1426
  /// given value.
1427 1427
  ///
1428 1428
  /// Writable bool map for filling each \c true assigned element with a 
1429 1429
  /// given value. The value can set the container.
1430 1430
  ///
1431 1431
  /// The following code finds the connected components of a graph
1432 1432
  /// and stores it in the \c comp map:
1433 1433
  ///\code
1434 1434
  /// typedef Graph::NodeMap<int> ComponentMap;
1435 1435
  /// ComponentMap comp(graph);
1436 1436
  /// typedef FillBoolMap<Graph::NodeMap<int> > ComponentFillerMap;
1437 1437
  /// ComponentFillerMap filler(comp, 0);
1438 1438
  ///
1439 1439
  /// Dfs<Graph>::DefProcessedMap<ComponentFillerMap>::Create dfs(graph);
1440 1440
  /// dfs.processedMap(filler);
1441 1441
  /// dfs.init();
1442 1442
  /// for (NodeIt it(graph); it != INVALID; ++it) {
0 comments (0 inline)