54 |
54 |
55 /// This map can be used if you have to provide a map only for |
55 /// This map can be used if you have to provide a map only for |
56 /// its type definitions, or if you have to provide a writable map, |
56 /// its type definitions, or if you have to provide a writable map, |
57 /// but data written to it is not required (i.e. it will be sent to |
57 /// but data written to it is not required (i.e. it will be sent to |
58 /// <tt>/dev/null</tt>). |
58 /// <tt>/dev/null</tt>). |
59 /// It conforms the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
59 /// It conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
60 /// |
60 /// |
61 /// \sa ConstMap |
61 /// \sa ConstMap |
62 template<typename K, typename V> |
62 template<typename K, typename V> |
63 class NullMap : public MapBase<K, V> { |
63 class NullMap : public MapBase<K, V> { |
64 public: |
64 public: |
87 |
87 |
88 /// This \ref concepts::ReadMap "readable map" assigns a specified |
88 /// This \ref concepts::ReadMap "readable map" assigns a specified |
89 /// value to each key. |
89 /// value to each key. |
90 /// |
90 /// |
91 /// In other aspects it is equivalent to \c NullMap. |
91 /// In other aspects it is equivalent to \c NullMap. |
92 /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap" |
92 /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" |
93 /// concept, but it absorbs the data written to it. |
93 /// concept, but it absorbs the data written to it. |
94 /// |
94 /// |
95 /// The simplest way of using this map is through the constMap() |
95 /// The simplest way of using this map is through the constMap() |
96 /// function. |
96 /// function. |
97 /// |
97 /// |
156 |
156 |
157 /// This \ref concepts::ReadMap "readable map" assigns a specified |
157 /// This \ref concepts::ReadMap "readable map" assigns a specified |
158 /// value to each key. |
158 /// value to each key. |
159 /// |
159 /// |
160 /// In other aspects it is equivalent to \c NullMap. |
160 /// In other aspects it is equivalent to \c NullMap. |
161 /// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap" |
161 /// So it conforms to the \ref concepts::ReadWriteMap "ReadWriteMap" |
162 /// concept, but it absorbs the data written to it. |
162 /// concept, but it absorbs the data written to it. |
163 /// |
163 /// |
164 /// The simplest way of using this map is through the constMap() |
164 /// The simplest way of using this map is through the constMap() |
165 /// function. |
165 /// function. |
166 /// |
166 /// |
230 /// |
230 /// |
231 /// This map is essentially a wrapper for \c std::vector. It assigns |
231 /// This map is essentially a wrapper for \c std::vector. It assigns |
232 /// values to integer keys from the range <tt>[0..size-1]</tt>. |
232 /// values to integer keys from the range <tt>[0..size-1]</tt>. |
233 /// It can be used with some data structures, for example |
233 /// It can be used with some data structures, for example |
234 /// \c UnionFind, \c BinHeap, when the used items are small |
234 /// \c UnionFind, \c BinHeap, when the used items are small |
235 /// integers. This map conforms the \ref concepts::ReferenceMap |
235 /// integers. This map conforms to the \ref concepts::ReferenceMap |
236 /// "ReferenceMap" concept. |
236 /// "ReferenceMap" concept. |
237 /// |
237 /// |
238 /// The simplest way of using this map is through the rangeMap() |
238 /// The simplest way of using this map is through the rangeMap() |
239 /// function. |
239 /// function. |
240 template <typename V> |
240 template <typename V> |
338 |
338 |
339 /// This map is essentially a wrapper for \c std::map with addition |
339 /// This map is essentially a wrapper for \c std::map with addition |
340 /// that you can specify a default value for the keys that are not |
340 /// that you can specify a default value for the keys that are not |
341 /// stored actually. This value can be different from the default |
341 /// stored actually. This value can be different from the default |
342 /// contructed value (i.e. \c %Value()). |
342 /// contructed value (i.e. \c %Value()). |
343 /// This type conforms the \ref concepts::ReferenceMap "ReferenceMap" |
343 /// This type conforms to the \ref concepts::ReferenceMap "ReferenceMap" |
344 /// concept. |
344 /// concept. |
345 /// |
345 /// |
346 /// This map is useful if a default value should be assigned to most of |
346 /// This map is useful if a default value should be assigned to most of |
347 /// the keys and different values should be assigned only to a few |
347 /// the keys and different values should be assigned only to a few |
348 /// keys (i.e. the map is "sparse"). |
348 /// keys (i.e. the map is "sparse"). |
704 |
704 |
705 /// Map adaptor to convert the \c Value type of a \ref concepts::ReadMap |
705 /// Map adaptor to convert the \c Value type of a \ref concepts::ReadMap |
706 /// "readable map" to another type using the default conversion. |
706 /// "readable map" to another type using the default conversion. |
707 /// The \c Key type of it is inherited from \c M and the \c Value |
707 /// The \c Key type of it is inherited from \c M and the \c Value |
708 /// type is \c V. |
708 /// type is \c V. |
709 /// This type conforms the \ref concepts::ReadMap "ReadMap" concept. |
709 /// This type conforms to the \ref concepts::ReadMap "ReadMap" concept. |
710 /// |
710 /// |
711 /// The simplest way of using this map is through the convertMap() |
711 /// The simplest way of using this map is through the convertMap() |
712 /// function. |
712 /// function. |
713 template <typename M, typename V> |
713 template <typename M, typename V> |
714 class ConvertMap : public MapBase<typename M::Key, V> { |
714 class ConvertMap : public MapBase<typename M::Key, V> { |
1880 /// \brief Constructor. |
1882 /// \brief Constructor. |
1881 /// |
1883 /// |
1882 /// Constructor for creating an id-to-item map. |
1884 /// Constructor for creating an id-to-item map. |
1883 explicit InverseMap(const IdMap& map) : _graph(map._graph) {} |
1885 explicit InverseMap(const IdMap& map) : _graph(map._graph) {} |
1884 |
1886 |
1885 /// \brief Gives back the given item from its id. |
1887 /// \brief Gives back an item by its id. |
1886 /// |
1888 /// |
1887 /// Gives back the given item from its id. |
1889 /// Gives back an item by its id. |
1888 Item operator[](int id) const { return _graph->fromId(id, Item());} |
1890 Item operator[](int id) const { return _graph->fromId(id, Item());} |
1889 |
1891 |
1890 private: |
1892 private: |
1891 const Graph* _graph; |
1893 const Graph* _graph; |
1892 }; |
1894 }; |
1901 /// \brief General cross reference graph map type. |
1903 /// \brief General cross reference graph map type. |
1902 |
1904 |
1903 /// This class provides simple invertable graph maps. |
1905 /// This class provides simple invertable graph maps. |
1904 /// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap) |
1906 /// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap) |
1905 /// and if a key is set to a new value, then stores it in the inverse map. |
1907 /// and if a key is set to a new value, then stores it in the inverse map. |
1906 /// The values of the map can be accessed |
1908 /// The graph items can be accessed by their values either using |
1907 /// with stl compatible forward iterator. |
1909 /// \c InverseMap or \c operator()(), and the values of the map can be |
|
1910 /// accessed with an STL compatible forward iterator (\c ValueIterator). |
|
1911 /// |
|
1912 /// This map is intended to be used when all associated values are |
|
1913 /// different (the map is actually invertable) or there are only a few |
|
1914 /// items with the same value. |
|
1915 /// Otherwise consider to use \c IterableValueMap, which is more |
|
1916 /// suitable and more efficient for such cases. It provides iterators |
|
1917 /// to traverse the items with the same associated value, however |
|
1918 /// it does not have \c InverseMap. |
1908 /// |
1919 /// |
1909 /// This type is not reference map, so it cannot be modified with |
1920 /// This type is not reference map, so it cannot be modified with |
1910 /// the subscript operator. |
1921 /// the subscript operator. |
1911 /// |
1922 /// |
1912 /// \tparam GR The graph type. |
1923 /// \tparam GR The graph type. |
1943 /// Construct a new CrossRefMap for the given graph. |
1954 /// Construct a new CrossRefMap for the given graph. |
1944 explicit CrossRefMap(const Graph& graph) : Map(graph) {} |
1955 explicit CrossRefMap(const Graph& graph) : Map(graph) {} |
1945 |
1956 |
1946 /// \brief Forward iterator for values. |
1957 /// \brief Forward iterator for values. |
1947 /// |
1958 /// |
1948 /// This iterator is an stl compatible forward |
1959 /// This iterator is an STL compatible forward |
1949 /// iterator on the values of the map. The values can |
1960 /// iterator on the values of the map. The values can |
1950 /// be accessed in the <tt>[beginValue, endValue)</tt> range. |
1961 /// be accessed in the <tt>[beginValue, endValue)</tt> range. |
1951 /// They are considered with multiplicity, so each value is |
1962 /// They are considered with multiplicity, so each value is |
1952 /// traversed for each item it is assigned to. |
1963 /// traversed for each item it is assigned to. |
1953 class ValueIterator |
1964 class ValueIterator |
1956 private: |
1967 private: |
1957 ValueIterator(typename Container::const_iterator _it) |
1968 ValueIterator(typename Container::const_iterator _it) |
1958 : it(_it) {} |
1969 : it(_it) {} |
1959 public: |
1970 public: |
1960 |
1971 |
|
1972 /// Constructor |
1961 ValueIterator() {} |
1973 ValueIterator() {} |
1962 |
1974 |
|
1975 /// \e |
1963 ValueIterator& operator++() { ++it; return *this; } |
1976 ValueIterator& operator++() { ++it; return *this; } |
|
1977 /// \e |
1964 ValueIterator operator++(int) { |
1978 ValueIterator operator++(int) { |
1965 ValueIterator tmp(*this); |
1979 ValueIterator tmp(*this); |
1966 operator++(); |
1980 operator++(); |
1967 return tmp; |
1981 return tmp; |
1968 } |
1982 } |
1969 |
1983 |
|
1984 /// \e |
1970 const Value& operator*() const { return it->first; } |
1985 const Value& operator*() const { return it->first; } |
|
1986 /// \e |
1971 const Value* operator->() const { return &(it->first); } |
1987 const Value* operator->() const { return &(it->first); } |
1972 |
1988 |
|
1989 /// \e |
1973 bool operator==(ValueIterator jt) const { return it == jt.it; } |
1990 bool operator==(ValueIterator jt) const { return it == jt.it; } |
|
1991 /// \e |
1974 bool operator!=(ValueIterator jt) const { return it != jt.it; } |
1992 bool operator!=(ValueIterator jt) const { return it != jt.it; } |
1975 |
1993 |
1976 private: |
1994 private: |
1977 typename Container::const_iterator it; |
1995 typename Container::const_iterator it; |
1978 }; |
1996 }; |
1979 |
1997 |
1980 /// \brief Returns an iterator to the first value. |
1998 /// \brief Returns an iterator to the first value. |
1981 /// |
1999 /// |
1982 /// Returns an stl compatible iterator to the |
2000 /// Returns an STL compatible iterator to the |
1983 /// first value of the map. The values of the |
2001 /// first value of the map. The values of the |
1984 /// map can be accessed in the <tt>[beginValue, endValue)</tt> |
2002 /// map can be accessed in the <tt>[beginValue, endValue)</tt> |
1985 /// range. |
2003 /// range. |
1986 ValueIterator beginValue() const { |
2004 ValueIterator beginValue() const { |
1987 return ValueIterator(_inv_map.begin()); |
2005 return ValueIterator(_inv_map.begin()); |
1988 } |
2006 } |
1989 |
2007 |
1990 /// \brief Returns an iterator after the last value. |
2008 /// \brief Returns an iterator after the last value. |
1991 /// |
2009 /// |
1992 /// Returns an stl compatible iterator after the |
2010 /// Returns an STL compatible iterator after the |
1993 /// last value of the map. The values of the |
2011 /// last value of the map. The values of the |
1994 /// map can be accessed in the <tt>[beginValue, endValue)</tt> |
2012 /// map can be accessed in the <tt>[beginValue, endValue)</tt> |
1995 /// range. |
2013 /// range. |
1996 ValueIterator endValue() const { |
2014 ValueIterator endValue() const { |
1997 return ValueIterator(_inv_map.end()); |
2015 return ValueIterator(_inv_map.end()); |
2270 _inv_map[qi] = p; |
2290 _inv_map[qi] = p; |
2271 Map::set(q, pi); |
2291 Map::set(q, pi); |
2272 _inv_map[pi] = q; |
2292 _inv_map[pi] = q; |
2273 } |
2293 } |
2274 |
2294 |
2275 /// \brief Gives back the \e RangeId of the item |
2295 /// \brief Gives back the \e range \e id of the item |
2276 /// |
2296 /// |
2277 /// Gives back the \e RangeId of the item. |
2297 /// Gives back the \e range \e id of the item. |
2278 int operator[](const Item& item) const { |
2298 int operator[](const Item& item) const { |
2279 return Map::operator[](item); |
2299 return Map::operator[](item); |
2280 } |
2300 } |
2281 |
2301 |
2282 /// \brief Gives back the item belonging to a \e RangeId |
2302 /// \brief Gives back the item belonging to a \e range \e id |
2283 /// |
2303 /// |
2284 /// Gives back the item belonging to a \e RangeId. |
2304 /// Gives back the item belonging to the given \e range \e id. |
2285 Item operator()(int id) const { |
2305 Item operator()(int id) const { |
2286 return _inv_map[id]; |
2306 return _inv_map[id]; |
2287 } |
2307 } |
2288 |
2308 |
2289 private: |
2309 private: |
2311 typedef typename RangeIdMap::Value Key; |
2333 typedef typename RangeIdMap::Value Key; |
2312 |
2334 |
2313 /// \brief Subscript operator. |
2335 /// \brief Subscript operator. |
2314 /// |
2336 /// |
2315 /// Subscript operator. It gives back the item |
2337 /// Subscript operator. It gives back the item |
2316 /// that the descriptor currently belongs to. |
2338 /// that the given \e range \e id currently belongs to. |
2317 Value operator[](const Key& key) const { |
2339 Value operator[](const Key& key) const { |
2318 return _inverted(key); |
2340 return _inverted(key); |
2319 } |
2341 } |
2320 |
2342 |
2321 /// \brief Size of the map. |
2343 /// \brief Size of the map. |
2329 const RangeIdMap& _inverted; |
2351 const RangeIdMap& _inverted; |
2330 }; |
2352 }; |
2331 |
2353 |
2332 /// \brief Gives back the inverse of the map. |
2354 /// \brief Gives back the inverse of the map. |
2333 /// |
2355 /// |
2334 /// Gives back the inverse of the map. |
2356 /// Gives back the inverse of the RangeIdMap. |
2335 const InverseMap inverse() const { |
2357 const InverseMap inverse() const { |
2336 return InverseMap(*this); |
2358 return InverseMap(*this); |
2337 } |
2359 } |
2338 }; |
2360 }; |
2339 |
2361 |
2340 /// \brief Dynamic iterable \c bool map. |
2362 /// \brief Dynamic iterable \c bool map. |
2341 /// |
2363 /// |
2342 /// This class provides a special graph map type which can store a |
2364 /// This class provides a special graph map type which can store a |
2343 /// \c bool value for graph items (\c Node, \c Arc or \c Edge). |
2365 /// \c bool value for graph items (\c Node, \c Arc or \c Edge). |
2344 /// For both \c true and \c false values it is possible to iterate on |
2366 /// For both \c true and \c false values it is possible to iterate on |
2345 /// the keys. |
2367 /// the keys mapped to the value. |
2346 /// |
2368 /// |
2347 /// This type is a reference map, so it can be modified with the |
2369 /// This type is a reference map, so it can be modified with the |
2348 /// subscription operator. |
2370 /// subscript operator. |
2349 /// |
2371 /// |
2350 /// \tparam GR The graph type. |
2372 /// \tparam GR The graph type. |
2351 /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or |
2373 /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or |
2352 /// \c GR::Edge). |
2374 /// \c GR::Edge). |
2353 /// |
2375 /// |
2709 /// This class provides a special graph map type which can store an |
2731 /// This class provides a special graph map type which can store an |
2710 /// integer value for graph items (\c Node, \c Arc or \c Edge). |
2732 /// integer value for graph items (\c Node, \c Arc or \c Edge). |
2711 /// For each non-negative value it is possible to iterate on the keys |
2733 /// For each non-negative value it is possible to iterate on the keys |
2712 /// mapped to the value. |
2734 /// mapped to the value. |
2713 /// |
2735 /// |
|
2736 /// This map is intended to be used with small integer values, for which |
|
2737 /// it is efficient, and supports iteration only for non-negative values. |
|
2738 /// If you need large values and/or iteration for negative integers, |
|
2739 /// consider to use \ref IterableValueMap instead. |
|
2740 /// |
2714 /// This type is a reference map, so it can be modified with the |
2741 /// This type is a reference map, so it can be modified with the |
2715 /// subscription operator. |
2742 /// subscript operator. |
2716 /// |
2743 /// |
2717 /// \note The size of the data structure depends on the largest |
2744 /// \note The size of the data structure depends on the largest |
2718 /// value in the map. |
2745 /// value in the map. |
2719 /// |
2746 /// |
2720 /// \tparam GR The graph type. |
2747 /// \tparam GR The graph type. |
2990 }; |
3017 }; |
2991 } |
3018 } |
2992 |
3019 |
2993 /// \brief Dynamic iterable map for comparable values. |
3020 /// \brief Dynamic iterable map for comparable values. |
2994 /// |
3021 /// |
2995 /// This class provides a special graph map type which can store an |
3022 /// This class provides a special graph map type which can store a |
2996 /// comparable value for graph items (\c Node, \c Arc or \c Edge). |
3023 /// comparable value for graph items (\c Node, \c Arc or \c Edge). |
2997 /// For each value it is possible to iterate on the keys mapped to |
3024 /// For each value it is possible to iterate on the keys mapped to |
2998 /// the value. |
3025 /// the value (\c ItemIt), and the values of the map can be accessed |
2999 /// |
3026 /// with an STL compatible forward iterator (\c ValueIterator). |
3000 /// The map stores for each value a linked list with |
3027 /// The map stores a linked list for each value, which contains |
3001 /// the items which mapped to the value, and the values are stored |
3028 /// the items mapped to the value, and the used values are stored |
3002 /// in balanced binary tree. The values of the map can be accessed |
3029 /// in balanced binary tree (\c std::map). |
3003 /// with stl compatible forward iterator. |
3030 /// |
|
3031 /// \ref IterableBoolMap and \ref IterableIntMap are similar classes |
|
3032 /// specialized for \c bool and \c int values, respectively. |
3004 /// |
3033 /// |
3005 /// This type is not reference map, so it cannot be modified with |
3034 /// This type is not reference map, so it cannot be modified with |
3006 /// the subscription operator. |
3035 /// the subscript operator. |
3007 /// |
3036 /// |
3008 /// \tparam GR The graph type. |
3037 /// \tparam GR The graph type. |
3009 /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or |
3038 /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or |
3010 /// \c GR::Edge). |
3039 /// \c GR::Edge). |
3011 /// \tparam V The value type of the map. It can be any comparable |
3040 /// \tparam V The value type of the map. It can be any comparable |
3077 |
3106 |
3078 public: |
3107 public: |
3079 |
3108 |
3080 /// \brief Forward iterator for values. |
3109 /// \brief Forward iterator for values. |
3081 /// |
3110 /// |
3082 /// This iterator is an stl compatible forward |
3111 /// This iterator is an STL compatible forward |
3083 /// iterator on the values of the map. The values can |
3112 /// iterator on the values of the map. The values can |
3084 /// be accessed in the <tt>[beginValue, endValue)</tt> range. |
3113 /// be accessed in the <tt>[beginValue, endValue)</tt> range. |
3085 class ValueIterator |
3114 class ValueIterator |
3086 : public std::iterator<std::forward_iterator_tag, Value> { |
3115 : public std::iterator<std::forward_iterator_tag, Value> { |
3087 friend class IterableValueMap; |
3116 friend class IterableValueMap; |
3088 private: |
3117 private: |
3089 ValueIterator(typename std::map<Value, Key>::const_iterator _it) |
3118 ValueIterator(typename std::map<Value, Key>::const_iterator _it) |
3090 : it(_it) {} |
3119 : it(_it) {} |
3091 public: |
3120 public: |
3092 |
3121 |
|
3122 /// Constructor |
3093 ValueIterator() {} |
3123 ValueIterator() {} |
3094 |
3124 |
|
3125 /// \e |
3095 ValueIterator& operator++() { ++it; return *this; } |
3126 ValueIterator& operator++() { ++it; return *this; } |
|
3127 /// \e |
3096 ValueIterator operator++(int) { |
3128 ValueIterator operator++(int) { |
3097 ValueIterator tmp(*this); |
3129 ValueIterator tmp(*this); |
3098 operator++(); |
3130 operator++(); |
3099 return tmp; |
3131 return tmp; |
3100 } |
3132 } |
3101 |
3133 |
|
3134 /// \e |
3102 const Value& operator*() const { return it->first; } |
3135 const Value& operator*() const { return it->first; } |
|
3136 /// \e |
3103 const Value* operator->() const { return &(it->first); } |
3137 const Value* operator->() const { return &(it->first); } |
3104 |
3138 |
|
3139 /// \e |
3105 bool operator==(ValueIterator jt) const { return it == jt.it; } |
3140 bool operator==(ValueIterator jt) const { return it == jt.it; } |
|
3141 /// \e |
3106 bool operator!=(ValueIterator jt) const { return it != jt.it; } |
3142 bool operator!=(ValueIterator jt) const { return it != jt.it; } |
3107 |
3143 |
3108 private: |
3144 private: |
3109 typename std::map<Value, Key>::const_iterator it; |
3145 typename std::map<Value, Key>::const_iterator it; |
3110 }; |
3146 }; |
3111 |
3147 |
3112 /// \brief Returns an iterator to the first value. |
3148 /// \brief Returns an iterator to the first value. |
3113 /// |
3149 /// |
3114 /// Returns an stl compatible iterator to the |
3150 /// Returns an STL compatible iterator to the |
3115 /// first value of the map. The values of the |
3151 /// first value of the map. The values of the |
3116 /// map can be accessed in the <tt>[beginValue, endValue)</tt> |
3152 /// map can be accessed in the <tt>[beginValue, endValue)</tt> |
3117 /// range. |
3153 /// range. |
3118 ValueIterator beginValue() const { |
3154 ValueIterator beginValue() const { |
3119 return ValueIterator(_first.begin()); |
3155 return ValueIterator(_first.begin()); |
3120 } |
3156 } |
3121 |
3157 |
3122 /// \brief Returns an iterator after the last value. |
3158 /// \brief Returns an iterator after the last value. |
3123 /// |
3159 /// |
3124 /// Returns an stl compatible iterator after the |
3160 /// Returns an STL compatible iterator after the |
3125 /// last value of the map. The values of the |
3161 /// last value of the map. The values of the |
3126 /// map can be accessed in the <tt>[beginValue, endValue)</tt> |
3162 /// map can be accessed in the <tt>[beginValue, endValue)</tt> |
3127 /// range. |
3163 /// range. |
3128 ValueIterator endValue() const { |
3164 ValueIterator endValue() const { |
3129 return ValueIterator(_first.end()); |
3165 return ValueIterator(_first.end()); |