| ... | ... |
@@ -680,264 +680,192 @@ |
| 680 | 680 |
MapToFunctor(const M &m) : _m(m) {}
|
| 681 | 681 |
/// \e |
| 682 | 682 |
Value operator()(const Key &k) const { return _m[k]; }
|
| 683 | 683 |
/// \e |
| 684 | 684 |
Value operator[](const Key &k) const { return _m[k]; }
|
| 685 | 685 |
}; |
| 686 | 686 |
|
| 687 | 687 |
/// Returns a \ref MapToFunctor class |
| 688 | 688 |
|
| 689 | 689 |
/// This function just returns a \ref MapToFunctor class. |
| 690 | 690 |
/// \relates MapToFunctor |
| 691 | 691 |
template<typename M> |
| 692 | 692 |
inline MapToFunctor<M> mapToFunctor(const M &m) {
|
| 693 | 693 |
return MapToFunctor<M>(m); |
| 694 | 694 |
} |
| 695 | 695 |
|
| 696 | 696 |
|
| 697 | 697 |
/// \brief Map adaptor to convert the \c Value type of a map to |
| 698 | 698 |
/// another type using the default conversion. |
| 699 | 699 |
|
| 700 | 700 |
/// Map adaptor to convert the \c Value type of a \ref concepts::ReadMap |
| 701 | 701 |
/// "readable map" to another type using the default conversion. |
| 702 | 702 |
/// The \c Key type of it is inherited from \c M and the \c Value |
| 703 | 703 |
/// type is \c V. |
| 704 | 704 |
/// This type conforms the \ref concepts::ReadMap "ReadMap" concept. |
| 705 | 705 |
/// |
| 706 | 706 |
/// The simplest way of using this map is through the convertMap() |
| 707 | 707 |
/// function. |
| 708 | 708 |
template <typename M, typename V> |
| 709 | 709 |
class ConvertMap : public MapBase<typename M::Key, V> {
|
| 710 | 710 |
const M &_m; |
| 711 | 711 |
public: |
| 712 | 712 |
typedef MapBase<typename M::Key, V> Parent; |
| 713 | 713 |
typedef typename Parent::Key Key; |
| 714 | 714 |
typedef typename Parent::Value Value; |
| 715 | 715 |
|
| 716 | 716 |
/// Constructor |
| 717 | 717 |
|
| 718 | 718 |
/// Constructor. |
| 719 | 719 |
/// \param m The underlying map. |
| 720 | 720 |
ConvertMap(const M &m) : _m(m) {}
|
| 721 | 721 |
|
| 722 | 722 |
/// \e |
| 723 | 723 |
Value operator[](const Key &k) const { return _m[k]; }
|
| 724 | 724 |
}; |
| 725 | 725 |
|
| 726 | 726 |
/// Returns a \ref ConvertMap class |
| 727 | 727 |
|
| 728 | 728 |
/// This function just returns a \ref ConvertMap class. |
| 729 | 729 |
/// \relates ConvertMap |
| 730 | 730 |
template<typename V, typename M> |
| 731 | 731 |
inline ConvertMap<M, V> convertMap(const M &map) {
|
| 732 | 732 |
return ConvertMap<M, V>(map); |
| 733 | 733 |
} |
| 734 | 734 |
|
| 735 | 735 |
|
| 736 | 736 |
/// Applies all map setting operations to two maps |
| 737 | 737 |
|
| 738 | 738 |
/// This map has two \ref concepts::WriteMap "writable map" parameters |
| 739 | 739 |
/// and each write request will be passed to both of them. |
| 740 | 740 |
/// If \c M1 is also \ref concepts::ReadMap "readable", then the read |
| 741 | 741 |
/// operations will return the corresponding values of \c M1. |
| 742 | 742 |
/// |
| 743 | 743 |
/// The \c Key and \c Value types are inherited from \c M1. |
| 744 | 744 |
/// The \c Key and \c Value of \c M2 must be convertible from those |
| 745 | 745 |
/// of \c M1. |
| 746 | 746 |
/// |
| 747 | 747 |
/// The simplest way of using this map is through the forkMap() |
| 748 | 748 |
/// function. |
| 749 | 749 |
template<typename M1, typename M2> |
| 750 | 750 |
class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 751 | 751 |
M1 &_m1; |
| 752 | 752 |
M2 &_m2; |
| 753 | 753 |
public: |
| 754 | 754 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 755 | 755 |
typedef typename Parent::Key Key; |
| 756 | 756 |
typedef typename Parent::Value Value; |
| 757 | 757 |
|
| 758 | 758 |
/// Constructor |
| 759 | 759 |
ForkMap(M1 &m1, M2 &m2) : _m1(m1), _m2(m2) {}
|
| 760 | 760 |
/// Returns the value associated with the given key in the first map. |
| 761 | 761 |
Value operator[](const Key &k) const { return _m1[k]; }
|
| 762 | 762 |
/// Sets the value associated with the given key in both maps. |
| 763 | 763 |
void set(const Key &k, const Value &v) { _m1.set(k,v); _m2.set(k,v); }
|
| 764 | 764 |
}; |
| 765 | 765 |
|
| 766 | 766 |
/// Returns a \ref ForkMap class |
| 767 | 767 |
|
| 768 | 768 |
/// This function just returns a \ref ForkMap class. |
| 769 | 769 |
/// \relates ForkMap |
| 770 | 770 |
template <typename M1, typename M2> |
| 771 | 771 |
inline ForkMap<M1,M2> forkMap(M1 &m1, M2 &m2) {
|
| 772 | 772 |
return ForkMap<M1,M2>(m1,m2); |
| 773 | 773 |
} |
| 774 | 774 |
|
| 775 | 775 |
|
| 776 |
/// Simple wrapping of a map |
|
| 777 |
|
|
| 778 |
/// This \ref concepts::ReadMap "read only map" returns the simple |
|
| 779 |
/// wrapping of the given map. Sometimes the reference maps cannot be |
|
| 780 |
/// combined with simple read maps. This map adaptor wraps the given |
|
| 781 |
/// map to simple read map. |
|
| 782 |
/// |
|
| 783 |
/// The simplest way of using this map is through the wrapMap() |
|
| 784 |
/// function. |
|
| 785 |
/// |
|
| 786 |
/// \sa WrapWriteMap |
|
| 787 |
template<typename M> |
|
| 788 |
class WrapMap : public MapBase<typename M::Key, typename M::Value> {
|
|
| 789 |
const M &_m; |
|
| 790 |
public: |
|
| 791 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
|
| 792 |
typedef typename Parent::Key Key; |
|
| 793 |
typedef typename Parent::Value Value; |
|
| 794 |
|
|
| 795 |
/// Constructor |
|
| 796 |
WrapMap(const M &m) : _m(m) {}
|
|
| 797 |
/// \e |
|
| 798 |
Value operator[](const Key &k) const { return _m[k]; }
|
|
| 799 |
}; |
|
| 800 |
|
|
| 801 |
/// Returns a \ref WrapMap class |
|
| 802 |
|
|
| 803 |
/// This function just returns a \ref WrapMap class. |
|
| 804 |
/// \relates WrapMap |
|
| 805 |
template<typename M> |
|
| 806 |
inline WrapMap<M> wrapMap(const M &map) {
|
|
| 807 |
return WrapMap<M>(map); |
|
| 808 |
} |
|
| 809 |
|
|
| 810 |
|
|
| 811 |
/// Simple writable wrapping of a map |
|
| 812 |
|
|
| 813 |
/// This \ref concepts::ReadWriteMap "read-write map" returns the simple |
|
| 814 |
/// wrapping of the given map. Sometimes the reference maps cannot be |
|
| 815 |
/// combined with simple read-write maps. This map adaptor wraps the |
|
| 816 |
/// given map to simple read-write map. |
|
| 817 |
/// |
|
| 818 |
/// The simplest way of using this map is through the wrapWriteMap() |
|
| 819 |
/// function. |
|
| 820 |
/// |
|
| 821 |
/// \sa WrapMap |
|
| 822 |
template<typename M> |
|
| 823 |
class WrapWriteMap : public MapBase<typename M::Key, typename M::Value> {
|
|
| 824 |
M &_m; |
|
| 825 |
public: |
|
| 826 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
|
| 827 |
typedef typename Parent::Key Key; |
|
| 828 |
typedef typename Parent::Value Value; |
|
| 829 |
|
|
| 830 |
/// Constructor |
|
| 831 |
WrapWriteMap(M &m) : _m(m) {}
|
|
| 832 |
/// \e |
|
| 833 |
Value operator[](const Key &k) const { return _m[k]; }
|
|
| 834 |
/// \e |
|
| 835 |
void set(const Key &k, const Value &c) { _m.set(k, c); }
|
|
| 836 |
}; |
|
| 837 |
|
|
| 838 |
///Returns a \ref WrapWriteMap class |
|
| 839 |
|
|
| 840 |
///This function just returns a \ref WrapWriteMap class. |
|
| 841 |
///\relates WrapWriteMap |
|
| 842 |
template<typename M> |
|
| 843 |
inline WrapWriteMap<M> wrapWriteMap(M &map) {
|
|
| 844 |
return WrapWriteMap<M>(map); |
|
| 845 |
} |
|
| 846 |
|
|
| 847 |
|
|
| 848 | 776 |
/// Sum of two maps |
| 849 | 777 |
|
| 850 | 778 |
/// This \ref concepts::ReadMap "read only map" returns the sum |
| 851 | 779 |
/// of the values of the two given maps. |
| 852 | 780 |
/// Its \c Key and \c Value types are inherited from \c M1. |
| 853 | 781 |
/// The \c Key and \c Value of \c M2 must be convertible to those of |
| 854 | 782 |
/// \c M1. |
| 855 | 783 |
/// |
| 856 | 784 |
/// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for |
| 857 | 785 |
/// \code |
| 858 | 786 |
/// AddMap<M1,M2> am(m1,m2); |
| 859 | 787 |
/// \endcode |
| 860 | 788 |
/// <tt>am[x]</tt> will be equal to <tt>m1[x]+m2[x]</tt>. |
| 861 | 789 |
/// |
| 862 | 790 |
/// The simplest way of using this map is through the addMap() |
| 863 | 791 |
/// function. |
| 864 | 792 |
/// |
| 865 | 793 |
/// \sa SubMap, MulMap, DivMap |
| 866 | 794 |
/// \sa ShiftMap, ShiftWriteMap |
| 867 | 795 |
template<typename M1, typename M2> |
| 868 | 796 |
class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 869 | 797 |
const M1 &_m1; |
| 870 | 798 |
const M2 &_m2; |
| 871 | 799 |
public: |
| 872 | 800 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 873 | 801 |
typedef typename Parent::Key Key; |
| 874 | 802 |
typedef typename Parent::Value Value; |
| 875 | 803 |
|
| 876 | 804 |
/// Constructor |
| 877 | 805 |
AddMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
|
| 878 | 806 |
/// \e |
| 879 | 807 |
Value operator[](const Key &k) const { return _m1[k]+_m2[k]; }
|
| 880 | 808 |
}; |
| 881 | 809 |
|
| 882 | 810 |
/// Returns an \ref AddMap class |
| 883 | 811 |
|
| 884 | 812 |
/// This function just returns an \ref AddMap class. |
| 885 | 813 |
/// |
| 886 | 814 |
/// For example, if \c m1 and \c m2 are both maps with \c double |
| 887 | 815 |
/// values, then <tt>addMap(m1,m2)[x]</tt> will be equal to |
| 888 | 816 |
/// <tt>m1[x]+m2[x]</tt>. |
| 889 | 817 |
/// |
| 890 | 818 |
/// \relates AddMap |
| 891 | 819 |
template<typename M1, typename M2> |
| 892 | 820 |
inline AddMap<M1, M2> addMap(const M1 &m1, const M2 &m2) {
|
| 893 | 821 |
return AddMap<M1, M2>(m1,m2); |
| 894 | 822 |
} |
| 895 | 823 |
|
| 896 | 824 |
|
| 897 | 825 |
/// Difference of two maps |
| 898 | 826 |
|
| 899 | 827 |
/// This \ref concepts::ReadMap "read only map" returns the difference |
| 900 | 828 |
/// of the values of the two given maps. |
| 901 | 829 |
/// Its \c Key and \c Value types are inherited from \c M1. |
| 902 | 830 |
/// The \c Key and \c Value of \c M2 must be convertible to those of |
| 903 | 831 |
/// \c M1. |
| 904 | 832 |
/// |
| 905 | 833 |
/// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for |
| 906 | 834 |
/// \code |
| 907 | 835 |
/// SubMap<M1,M2> sm(m1,m2); |
| 908 | 836 |
/// \endcode |
| 909 | 837 |
/// <tt>sm[x]</tt> will be equal to <tt>m1[x]-m2[x]</tt>. |
| 910 | 838 |
/// |
| 911 | 839 |
/// The simplest way of using this map is through the subMap() |
| 912 | 840 |
/// function. |
| 913 | 841 |
/// |
| 914 | 842 |
/// \sa AddMap, MulMap, DivMap |
| 915 | 843 |
template<typename M1, typename M2> |
| 916 | 844 |
class SubMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 917 | 845 |
const M1 &_m1; |
| 918 | 846 |
const M2 &_m2; |
| 919 | 847 |
public: |
| 920 | 848 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 921 | 849 |
typedef typename Parent::Key Key; |
| 922 | 850 |
typedef typename Parent::Value Value; |
| 923 | 851 |
|
| 924 | 852 |
/// Constructor |
| 925 | 853 |
SubMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
|
| 926 | 854 |
/// \e |
| 927 | 855 |
Value operator[](const Key &k) const { return _m1[k]-_m2[k]; }
|
| 928 | 856 |
}; |
| 929 | 857 |
|
| 930 | 858 |
/// Returns a \ref SubMap class |
| 931 | 859 |
|
| 932 | 860 |
/// This function just returns a \ref SubMap class. |
| 933 | 861 |
/// |
| 934 | 862 |
/// For example, if \c m1 and \c m2 are both maps with \c double |
| 935 | 863 |
/// values, then <tt>subMap(m1,m2)[x]</tt> will be equal to |
| 936 | 864 |
/// <tt>m1[x]-m2[x]</tt>. |
| 937 | 865 |
/// |
| 938 | 866 |
/// \relates SubMap |
| 939 | 867 |
template<typename M1, typename M2> |
| 940 | 868 |
inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) {
|
| 941 | 869 |
return SubMap<M1, M2>(m1,m2); |
| 942 | 870 |
} |
| 943 | 871 |
|
| ... | ... |
@@ -1370,476 +1298,100 @@ |
| 1370 | 1298 |
|
| 1371 | 1299 |
/// Returns an \ref AbsMap class |
| 1372 | 1300 |
|
| 1373 | 1301 |
/// This function just returns an \ref AbsMap class. |
| 1374 | 1302 |
/// |
| 1375 | 1303 |
/// For example, if \c m is a map with \c double values, then |
| 1376 | 1304 |
/// <tt>absMap(m)[x]</tt> will be equal to <tt>m[x]</tt> if |
| 1377 | 1305 |
/// it is positive or zero and <tt>-m[x]</tt> if <tt>m[x]</tt> is |
| 1378 | 1306 |
/// negative. |
| 1379 | 1307 |
/// |
| 1380 | 1308 |
/// \relates AbsMap |
| 1381 | 1309 |
template<typename M> |
| 1382 | 1310 |
inline AbsMap<M> absMap(const M &m) {
|
| 1383 | 1311 |
return AbsMap<M>(m); |
| 1384 | 1312 |
} |
| 1385 | 1313 |
|
| 1386 | 1314 |
|
| 1387 | 1315 |
/// Logical 'not' of a map |
| 1388 | 1316 |
|
| 1389 | 1317 |
/// This \ref concepts::ReadMap "read only map" returns the logical |
| 1390 | 1318 |
/// negation of the values of the given map. |
| 1391 | 1319 |
/// Its \c Key is inherited from \c M and its \c Value is \c bool. |
| 1392 | 1320 |
/// |
| 1393 | 1321 |
/// The simplest way of using this map is through the notMap() |
| 1394 | 1322 |
/// function. |
| 1395 | 1323 |
/// |
| 1396 | 1324 |
/// \sa NotWriteMap |
| 1397 | 1325 |
template <typename M> |
| 1398 | 1326 |
class NotMap : public MapBase<typename M::Key, bool> {
|
| 1399 | 1327 |
const M &_m; |
| 1400 | 1328 |
public: |
| 1401 | 1329 |
typedef MapBase<typename M::Key, bool> Parent; |
| 1402 | 1330 |
typedef typename Parent::Key Key; |
| 1403 | 1331 |
typedef typename Parent::Value Value; |
| 1404 | 1332 |
|
| 1405 | 1333 |
/// Constructor |
| 1406 | 1334 |
NotMap(const M &m) : _m(m) {}
|
| 1407 | 1335 |
/// \e |
| 1408 | 1336 |
Value operator[](const Key &k) const { return !_m[k]; }
|
| 1409 | 1337 |
}; |
| 1410 | 1338 |
|
| 1411 | 1339 |
/// Logical 'not' of a map (read-write version) |
| 1412 | 1340 |
|
| 1413 | 1341 |
/// This \ref concepts::ReadWriteMap "read-write map" returns the |
| 1414 | 1342 |
/// logical negation of the values of the given map. |
| 1415 | 1343 |
/// Its \c Key is inherited from \c M and its \c Value is \c bool. |
| 1416 | 1344 |
/// It makes also possible to write the map. When a value is set, |
| 1417 | 1345 |
/// the opposite value is set to the original map. |
| 1418 | 1346 |
/// |
| 1419 | 1347 |
/// The simplest way of using this map is through the notWriteMap() |
| 1420 | 1348 |
/// function. |
| 1421 | 1349 |
/// |
| 1422 | 1350 |
/// \sa NotMap |
| 1423 | 1351 |
template <typename M> |
| 1424 | 1352 |
class NotWriteMap : public MapBase<typename M::Key, bool> {
|
| 1425 | 1353 |
M &_m; |
| 1426 | 1354 |
public: |
| 1427 | 1355 |
typedef MapBase<typename M::Key, bool> Parent; |
| 1428 | 1356 |
typedef typename Parent::Key Key; |
| 1429 | 1357 |
typedef typename Parent::Value Value; |
| 1430 | 1358 |
|
| 1431 | 1359 |
/// Constructor |
| 1432 | 1360 |
NotWriteMap(M &m) : _m(m) {}
|
| 1433 | 1361 |
/// \e |
| 1434 | 1362 |
Value operator[](const Key &k) const { return !_m[k]; }
|
| 1435 | 1363 |
/// \e |
| 1436 | 1364 |
void set(const Key &k, bool v) { _m.set(k, !v); }
|
| 1437 | 1365 |
}; |
| 1438 | 1366 |
|
| 1439 | 1367 |
/// Returns a \ref NotMap class |
| 1440 | 1368 |
|
| 1441 | 1369 |
/// This function just returns a \ref NotMap class. |
| 1442 | 1370 |
/// |
| 1443 | 1371 |
/// For example, if \c m is a map with \c bool values, then |
| 1444 | 1372 |
/// <tt>notMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>. |
| 1445 | 1373 |
/// |
| 1446 | 1374 |
/// \relates NotMap |
| 1447 | 1375 |
template <typename M> |
| 1448 | 1376 |
inline NotMap<M> notMap(const M &m) {
|
| 1449 | 1377 |
return NotMap<M>(m); |
| 1450 | 1378 |
} |
| 1451 | 1379 |
|
| 1452 | 1380 |
/// Returns a \ref NotWriteMap class |
| 1453 | 1381 |
|
| 1454 | 1382 |
/// This function just returns a \ref NotWriteMap class. |
| 1455 | 1383 |
/// |
| 1456 | 1384 |
/// For example, if \c m is a map with \c bool values, then |
| 1457 | 1385 |
/// <tt>notWriteMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>. |
| 1458 | 1386 |
/// Moreover it makes also possible to write the map. |
| 1459 | 1387 |
/// |
| 1460 | 1388 |
/// \relates NotWriteMap |
| 1461 | 1389 |
template <typename M> |
| 1462 | 1390 |
inline NotWriteMap<M> notWriteMap(M &m) {
|
| 1463 | 1391 |
return NotWriteMap<M>(m); |
| 1464 | 1392 |
} |
| 1465 | 1393 |
|
| 1466 |
|
|
| 1467 |
namespace _maps_bits {
|
|
| 1468 |
|
|
| 1469 |
template <typename Value> |
|
| 1470 |
struct Identity {
|
|
| 1471 |
typedef Value argument_type; |
|
| 1472 |
typedef Value result_type; |
|
| 1473 |
Value operator()(const Value& val) const {
|
|
| 1474 |
return val; |
|
| 1475 |
} |
|
| 1476 |
}; |
|
| 1477 |
|
|
| 1478 |
template <typename _Iterator, typename Enable = void> |
|
| 1479 |
struct IteratorTraits {
|
|
| 1480 |
typedef typename std::iterator_traits<_Iterator>::value_type Value; |
|
| 1481 |
}; |
|
| 1482 |
|
|
| 1483 |
template <typename _Iterator> |
|
| 1484 |
struct IteratorTraits<_Iterator, |
|
| 1485 |
typename exists<typename _Iterator::container_type>::type> |
|
| 1486 |
{
|
|
| 1487 |
typedef typename _Iterator::container_type::value_type Value; |
|
| 1488 |
}; |
|
| 1489 |
|
|
| 1490 |
} |
|
| 1491 |
|
|
| 1492 |
|
|
| 1493 |
/// \brief Writable bool map for logging each \c true assigned element |
|
| 1494 |
/// |
|
| 1495 |
/// A \ref concepts::ReadWriteMap "read-write" bool map for logging |
|
| 1496 |
/// each \c true assigned element, i.e it copies all the keys set |
|
| 1497 |
/// to \c true to the given iterator. |
|
| 1498 |
/// |
|
| 1499 |
/// \note The container of the iterator should contain space |
|
| 1500 |
/// for each element. |
|
| 1501 |
/// |
|
| 1502 |
/// The following example shows how you can write the edges found by |
|
| 1503 |
/// the \ref Prim algorithm directly to the standard output. |
|
| 1504 |
/// \code |
|
| 1505 |
/// typedef IdMap<Graph, Edge> EdgeIdMap; |
|
| 1506 |
/// EdgeIdMap edgeId(graph); |
|
| 1507 |
/// |
|
| 1508 |
/// typedef MapToFunctor<EdgeIdMap> EdgeIdFunctor; |
|
| 1509 |
/// EdgeIdFunctor edgeIdFunctor(edgeId); |
|
| 1510 |
/// |
|
| 1511 |
/// StoreBoolMap<ostream_iterator<int>, EdgeIdFunctor> |
|
| 1512 |
/// writerMap(ostream_iterator<int>(cout, " "), edgeIdFunctor); |
|
| 1513 |
/// |
|
| 1514 |
/// prim(graph, cost, writerMap); |
|
| 1515 |
/// \endcode |
|
| 1516 |
/// |
|
| 1517 |
/// \sa BackInserterBoolMap |
|
| 1518 |
/// \sa FrontInserterBoolMap |
|
| 1519 |
/// \sa InserterBoolMap |
|
| 1520 |
/// |
|
| 1521 |
/// \todo Revise the name of this class and the related ones. |
|
| 1522 |
template <typename _Iterator, |
|
| 1523 |
typename _Functor = |
|
| 1524 |
_maps_bits::Identity<typename _maps_bits:: |
|
| 1525 |
IteratorTraits<_Iterator>::Value> > |
|
| 1526 |
class StoreBoolMap {
|
|
| 1527 |
public: |
|
| 1528 |
typedef _Iterator Iterator; |
|
| 1529 |
|
|
| 1530 |
typedef typename _Functor::argument_type Key; |
|
| 1531 |
typedef bool Value; |
|
| 1532 |
|
|
| 1533 |
typedef _Functor Functor; |
|
| 1534 |
|
|
| 1535 |
/// Constructor |
|
| 1536 |
StoreBoolMap(Iterator it, const Functor& functor = Functor()) |
|
| 1537 |
: _begin(it), _end(it), _functor(functor) {}
|
|
| 1538 |
|
|
| 1539 |
/// Gives back the given iterator set for the first key |
|
| 1540 |
Iterator begin() const {
|
|
| 1541 |
return _begin; |
|
| 1542 |
} |
|
| 1543 |
|
|
| 1544 |
/// Gives back the the 'after the last' iterator |
|
| 1545 |
Iterator end() const {
|
|
| 1546 |
return _end; |
|
| 1547 |
} |
|
| 1548 |
|
|
| 1549 |
/// The set function of the map |
|
| 1550 |
void set(const Key& key, Value value) const {
|
|
| 1551 |
if (value) {
|
|
| 1552 |
*_end++ = _functor(key); |
|
| 1553 |
} |
|
| 1554 |
} |
|
| 1555 |
|
|
| 1556 |
private: |
|
| 1557 |
Iterator _begin; |
|
| 1558 |
mutable Iterator _end; |
|
| 1559 |
Functor _functor; |
|
| 1560 |
}; |
|
| 1561 |
|
|
| 1562 |
/// \brief Writable bool map for logging each \c true assigned element in |
|
| 1563 |
/// a back insertable container. |
|
| 1564 |
/// |
|
| 1565 |
/// Writable bool map for logging each \c true assigned element by pushing |
|
| 1566 |
/// them into a back insertable container. |
|
| 1567 |
/// It can be used to retrieve the items into a standard |
|
| 1568 |
/// container. The next example shows how you can store the |
|
| 1569 |
/// edges found by the Prim algorithm in a vector. |
|
| 1570 |
/// |
|
| 1571 |
/// \code |
|
| 1572 |
/// vector<Edge> span_tree_edges; |
|
| 1573 |
/// BackInserterBoolMap<vector<Edge> > inserter_map(span_tree_edges); |
|
| 1574 |
/// prim(graph, cost, inserter_map); |
|
| 1575 |
/// \endcode |
|
| 1576 |
/// |
|
| 1577 |
/// \sa StoreBoolMap |
|
| 1578 |
/// \sa FrontInserterBoolMap |
|
| 1579 |
/// \sa InserterBoolMap |
|
| 1580 |
template <typename Container, |
|
| 1581 |
typename Functor = |
|
| 1582 |
_maps_bits::Identity<typename Container::value_type> > |
|
| 1583 |
class BackInserterBoolMap {
|
|
| 1584 |
public: |
|
| 1585 |
typedef typename Functor::argument_type Key; |
|
| 1586 |
typedef bool Value; |
|
| 1587 |
|
|
| 1588 |
/// Constructor |
|
| 1589 |
BackInserterBoolMap(Container& _container, |
|
| 1590 |
const Functor& _functor = Functor()) |
|
| 1591 |
: container(_container), functor(_functor) {}
|
|
| 1592 |
|
|
| 1593 |
/// The set function of the map |
|
| 1594 |
void set(const Key& key, Value value) {
|
|
| 1595 |
if (value) {
|
|
| 1596 |
container.push_back(functor(key)); |
|
| 1597 |
} |
|
| 1598 |
} |
|
| 1599 |
|
|
| 1600 |
private: |
|
| 1601 |
Container& container; |
|
| 1602 |
Functor functor; |
|
| 1603 |
}; |
|
| 1604 |
|
|
| 1605 |
/// \brief Writable bool map for logging each \c true assigned element in |
|
| 1606 |
/// a front insertable container. |
|
| 1607 |
/// |
|
| 1608 |
/// Writable bool map for logging each \c true assigned element by pushing |
|
| 1609 |
/// them into a front insertable container. |
|
| 1610 |
/// It can be used to retrieve the items into a standard |
|
| 1611 |
/// container. For example see \ref BackInserterBoolMap. |
|
| 1612 |
/// |
|
| 1613 |
/// \sa BackInserterBoolMap |
|
| 1614 |
/// \sa InserterBoolMap |
|
| 1615 |
template <typename Container, |
|
| 1616 |
typename Functor = |
|
| 1617 |
_maps_bits::Identity<typename Container::value_type> > |
|
| 1618 |
class FrontInserterBoolMap {
|
|
| 1619 |
public: |
|
| 1620 |
typedef typename Functor::argument_type Key; |
|
| 1621 |
typedef bool Value; |
|
| 1622 |
|
|
| 1623 |
/// Constructor |
|
| 1624 |
FrontInserterBoolMap(Container& _container, |
|
| 1625 |
const Functor& _functor = Functor()) |
|
| 1626 |
: container(_container), functor(_functor) {}
|
|
| 1627 |
|
|
| 1628 |
/// The set function of the map |
|
| 1629 |
void set(const Key& key, Value value) {
|
|
| 1630 |
if (value) {
|
|
| 1631 |
container.push_front(functor(key)); |
|
| 1632 |
} |
|
| 1633 |
} |
|
| 1634 |
|
|
| 1635 |
private: |
|
| 1636 |
Container& container; |
|
| 1637 |
Functor functor; |
|
| 1638 |
}; |
|
| 1639 |
|
|
| 1640 |
/// \brief Writable bool map for storing each \c true assigned element in |
|
| 1641 |
/// an insertable container. |
|
| 1642 |
/// |
|
| 1643 |
/// Writable bool map for storing each \c true assigned element in an |
|
| 1644 |
/// insertable container. It will insert all the keys set to \c true into |
|
| 1645 |
/// the container. |
|
| 1646 |
/// |
|
| 1647 |
/// For example, if you want to store the cut arcs of the strongly |
|
| 1648 |
/// connected components in a set you can use the next code: |
|
| 1649 |
/// |
|
| 1650 |
/// \code |
|
| 1651 |
/// set<Arc> cut_arcs; |
|
| 1652 |
/// InserterBoolMap<set<Arc> > inserter_map(cut_arcs); |
|
| 1653 |
/// stronglyConnectedCutArcs(digraph, cost, inserter_map); |
|
| 1654 |
/// \endcode |
|
| 1655 |
/// |
|
| 1656 |
/// \sa BackInserterBoolMap |
|
| 1657 |
/// \sa FrontInserterBoolMap |
|
| 1658 |
template <typename Container, |
|
| 1659 |
typename Functor = |
|
| 1660 |
_maps_bits::Identity<typename Container::value_type> > |
|
| 1661 |
class InserterBoolMap {
|
|
| 1662 |
public: |
|
| 1663 |
typedef typename Container::value_type Key; |
|
| 1664 |
typedef bool Value; |
|
| 1665 |
|
|
| 1666 |
/// Constructor with specified iterator |
|
| 1667 |
|
|
| 1668 |
/// Constructor with specified iterator. |
|
| 1669 |
/// \param _container The container for storing the elements. |
|
| 1670 |
/// \param _it The elements will be inserted before this iterator. |
|
| 1671 |
/// \param _functor The functor that is used when an element is stored. |
|
| 1672 |
InserterBoolMap(Container& _container, typename Container::iterator _it, |
|
| 1673 |
const Functor& _functor = Functor()) |
|
| 1674 |
: container(_container), it(_it), functor(_functor) {}
|
|
| 1675 |
|
|
| 1676 |
/// Constructor |
|
| 1677 |
|
|
| 1678 |
/// Constructor without specified iterator. |
|
| 1679 |
/// The elements will be inserted before <tt>_container.end()</tt>. |
|
| 1680 |
/// \param _container The container for storing the elements. |
|
| 1681 |
/// \param _functor The functor that is used when an element is stored. |
|
| 1682 |
InserterBoolMap(Container& _container, const Functor& _functor = Functor()) |
|
| 1683 |
: container(_container), it(_container.end()), functor(_functor) {}
|
|
| 1684 |
|
|
| 1685 |
/// The set function of the map |
|
| 1686 |
void set(const Key& key, Value value) {
|
|
| 1687 |
if (value) {
|
|
| 1688 |
it = container.insert(it, functor(key)); |
|
| 1689 |
++it; |
|
| 1690 |
} |
|
| 1691 |
} |
|
| 1692 |
|
|
| 1693 |
private: |
|
| 1694 |
Container& container; |
|
| 1695 |
typename Container::iterator it; |
|
| 1696 |
Functor functor; |
|
| 1697 |
}; |
|
| 1698 |
|
|
| 1699 |
/// \brief Writable bool map for filling each \c true assigned element with a |
|
| 1700 |
/// given value. |
|
| 1701 |
/// |
|
| 1702 |
/// Writable bool map for filling each \c true assigned element with a |
|
| 1703 |
/// given value. The value can set the container. |
|
| 1704 |
/// |
|
| 1705 |
/// The following code finds the connected components of a graph |
|
| 1706 |
/// and stores it in the \c comp map: |
|
| 1707 |
/// \code |
|
| 1708 |
/// typedef Graph::NodeMap<int> ComponentMap; |
|
| 1709 |
/// ComponentMap comp(graph); |
|
| 1710 |
/// typedef FillBoolMap<Graph::NodeMap<int> > ComponentFillerMap; |
|
| 1711 |
/// ComponentFillerMap filler(comp, 0); |
|
| 1712 |
/// |
|
| 1713 |
/// Dfs<Graph>::DefProcessedMap<ComponentFillerMap>::Create dfs(graph); |
|
| 1714 |
/// dfs.processedMap(filler); |
|
| 1715 |
/// dfs.init(); |
|
| 1716 |
/// for (NodeIt it(graph); it != INVALID; ++it) {
|
|
| 1717 |
/// if (!dfs.reached(it)) {
|
|
| 1718 |
/// dfs.addSource(it); |
|
| 1719 |
/// dfs.start(); |
|
| 1720 |
/// ++filler.fillValue(); |
|
| 1721 |
/// } |
|
| 1722 |
/// } |
|
| 1723 |
/// \endcode |
|
| 1724 |
template <typename Map> |
|
| 1725 |
class FillBoolMap {
|
|
| 1726 |
public: |
|
| 1727 |
typedef typename Map::Key Key; |
|
| 1728 |
typedef bool Value; |
|
| 1729 |
|
|
| 1730 |
/// Constructor |
|
| 1731 |
FillBoolMap(Map& _map, const typename Map::Value& _fill) |
|
| 1732 |
: map(_map), fill(_fill) {}
|
|
| 1733 |
|
|
| 1734 |
/// Constructor |
|
| 1735 |
FillBoolMap(Map& _map) |
|
| 1736 |
: map(_map), fill() {}
|
|
| 1737 |
|
|
| 1738 |
/// Gives back the current fill value |
|
| 1739 |
const typename Map::Value& fillValue() const {
|
|
| 1740 |
return fill; |
|
| 1741 |
} |
|
| 1742 |
|
|
| 1743 |
/// Gives back the current fill value |
|
| 1744 |
typename Map::Value& fillValue() {
|
|
| 1745 |
return fill; |
|
| 1746 |
} |
|
| 1747 |
|
|
| 1748 |
/// Sets the current fill value |
|
| 1749 |
void fillValue(const typename Map::Value& _fill) {
|
|
| 1750 |
fill = _fill; |
|
| 1751 |
} |
|
| 1752 |
|
|
| 1753 |
/// The set function of the map |
|
| 1754 |
void set(const Key& key, Value value) {
|
|
| 1755 |
if (value) {
|
|
| 1756 |
map.set(key, fill); |
|
| 1757 |
} |
|
| 1758 |
} |
|
| 1759 |
|
|
| 1760 |
private: |
|
| 1761 |
Map& map; |
|
| 1762 |
typename Map::Value fill; |
|
| 1763 |
}; |
|
| 1764 |
|
|
| 1765 |
|
|
| 1766 |
/// \brief Writable bool map for storing the sequence number of |
|
| 1767 |
/// \c true assignments. |
|
| 1768 |
/// |
|
| 1769 |
/// Writable bool map that stores for each \c true assigned elements |
|
| 1770 |
/// the sequence number of this setting. |
|
| 1771 |
/// It makes it easy to calculate the leaving |
|
| 1772 |
/// order of the nodes in the \ref Dfs algorithm. |
|
| 1773 |
/// |
|
| 1774 |
/// \code |
|
| 1775 |
/// typedef Digraph::NodeMap<int> OrderMap; |
|
| 1776 |
/// OrderMap order(digraph); |
|
| 1777 |
/// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap; |
|
| 1778 |
/// OrderSetterMap setter(order); |
|
| 1779 |
/// Dfs<Digraph>::DefProcessedMap<OrderSetterMap>::Create dfs(digraph); |
|
| 1780 |
/// dfs.processedMap(setter); |
|
| 1781 |
/// dfs.init(); |
|
| 1782 |
/// for (NodeIt it(digraph); it != INVALID; ++it) {
|
|
| 1783 |
/// if (!dfs.reached(it)) {
|
|
| 1784 |
/// dfs.addSource(it); |
|
| 1785 |
/// dfs.start(); |
|
| 1786 |
/// } |
|
| 1787 |
/// } |
|
| 1788 |
/// \endcode |
|
| 1789 |
/// |
|
| 1790 |
/// The storing of the discovering order is more difficult because the |
|
| 1791 |
/// ReachedMap should be readable in the dfs algorithm but the setting |
|
| 1792 |
/// order map is not readable. Thus we must use the fork map: |
|
| 1793 |
/// |
|
| 1794 |
/// \code |
|
| 1795 |
/// typedef Digraph::NodeMap<int> OrderMap; |
|
| 1796 |
/// OrderMap order(digraph); |
|
| 1797 |
/// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap; |
|
| 1798 |
/// OrderSetterMap setter(order); |
|
| 1799 |
/// typedef Digraph::NodeMap<bool> StoreMap; |
|
| 1800 |
/// StoreMap store(digraph); |
|
| 1801 |
/// |
|
| 1802 |
/// typedef ForkMap<StoreMap, OrderSetterMap> ReachedMap; |
|
| 1803 |
/// ReachedMap reached(store, setter); |
|
| 1804 |
/// |
|
| 1805 |
/// Dfs<Digraph>::DefReachedMap<ReachedMap>::Create dfs(digraph); |
|
| 1806 |
/// dfs.reachedMap(reached); |
|
| 1807 |
/// dfs.init(); |
|
| 1808 |
/// for (NodeIt it(digraph); it != INVALID; ++it) {
|
|
| 1809 |
/// if (!dfs.reached(it)) {
|
|
| 1810 |
/// dfs.addSource(it); |
|
| 1811 |
/// dfs.start(); |
|
| 1812 |
/// } |
|
| 1813 |
/// } |
|
| 1814 |
/// \endcode |
|
| 1815 |
template <typename Map> |
|
| 1816 |
class SettingOrderBoolMap {
|
|
| 1817 |
public: |
|
| 1818 |
typedef typename Map::Key Key; |
|
| 1819 |
typedef bool Value; |
|
| 1820 |
|
|
| 1821 |
/// Constructor |
|
| 1822 |
SettingOrderBoolMap(Map& _map) |
|
| 1823 |
: map(_map), counter(0) {}
|
|
| 1824 |
|
|
| 1825 |
/// Number of set operations. |
|
| 1826 |
int num() const {
|
|
| 1827 |
return counter; |
|
| 1828 |
} |
|
| 1829 |
|
|
| 1830 |
/// The set function of the map |
|
| 1831 |
void set(const Key& key, Value value) {
|
|
| 1832 |
if (value) {
|
|
| 1833 |
map.set(key, counter++); |
|
| 1834 |
} |
|
| 1835 |
} |
|
| 1836 |
|
|
| 1837 |
private: |
|
| 1838 |
Map& map; |
|
| 1839 |
int counter; |
|
| 1840 |
}; |
|
| 1841 |
|
|
| 1842 | 1394 |
/// @} |
| 1843 | 1395 |
} |
| 1844 | 1396 |
|
| 1845 | 1397 |
#endif // LEMON_MAPS_H |
0 comments (0 inline)