0
3
0
| ... | ... |
@@ -40,290 +40,290 @@ |
| 40 | 40 |
namespace lemon {
|
| 41 | 41 |
|
| 42 | 42 |
namespace _kruskal_bits {
|
| 43 | 43 |
|
| 44 | 44 |
// Kruskal for directed graphs. |
| 45 | 45 |
|
| 46 | 46 |
template <typename Digraph, typename In, typename Out> |
| 47 | 47 |
typename disable_if<lemon::UndirectedTagIndicator<Digraph>, |
| 48 | 48 |
typename In::value_type::second_type >::type |
| 49 | 49 |
kruskal(const Digraph& digraph, const In& in, Out& out,dummy<0> = 0) {
|
| 50 | 50 |
typedef typename In::value_type::second_type Value; |
| 51 | 51 |
typedef typename Digraph::template NodeMap<int> IndexMap; |
| 52 | 52 |
typedef typename Digraph::Node Node; |
| 53 | 53 |
|
| 54 | 54 |
IndexMap index(digraph); |
| 55 | 55 |
UnionFind<IndexMap> uf(index); |
| 56 | 56 |
for (typename Digraph::NodeIt it(digraph); it != INVALID; ++it) {
|
| 57 | 57 |
uf.insert(it); |
| 58 | 58 |
} |
| 59 | 59 |
|
| 60 | 60 |
Value tree_value = 0; |
| 61 | 61 |
for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) {
|
| 62 | 62 |
if (uf.join(digraph.target(it->first),digraph.source(it->first))) {
|
| 63 | 63 |
out.set(it->first, true); |
| 64 | 64 |
tree_value += it->second; |
| 65 | 65 |
} |
| 66 | 66 |
else {
|
| 67 | 67 |
out.set(it->first, false); |
| 68 | 68 |
} |
| 69 | 69 |
} |
| 70 | 70 |
return tree_value; |
| 71 | 71 |
} |
| 72 | 72 |
|
| 73 | 73 |
// Kruskal for undirected graphs. |
| 74 | 74 |
|
| 75 | 75 |
template <typename Graph, typename In, typename Out> |
| 76 | 76 |
typename enable_if<lemon::UndirectedTagIndicator<Graph>, |
| 77 | 77 |
typename In::value_type::second_type >::type |
| 78 | 78 |
kruskal(const Graph& graph, const In& in, Out& out,dummy<1> = 1) {
|
| 79 | 79 |
typedef typename In::value_type::second_type Value; |
| 80 | 80 |
typedef typename Graph::template NodeMap<int> IndexMap; |
| 81 | 81 |
typedef typename Graph::Node Node; |
| 82 | 82 |
|
| 83 | 83 |
IndexMap index(graph); |
| 84 | 84 |
UnionFind<IndexMap> uf(index); |
| 85 | 85 |
for (typename Graph::NodeIt it(graph); it != INVALID; ++it) {
|
| 86 | 86 |
uf.insert(it); |
| 87 | 87 |
} |
| 88 | 88 |
|
| 89 | 89 |
Value tree_value = 0; |
| 90 | 90 |
for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) {
|
| 91 | 91 |
if (uf.join(graph.u(it->first),graph.v(it->first))) {
|
| 92 | 92 |
out.set(it->first, true); |
| 93 | 93 |
tree_value += it->second; |
| 94 | 94 |
} |
| 95 | 95 |
else {
|
| 96 | 96 |
out.set(it->first, false); |
| 97 | 97 |
} |
| 98 | 98 |
} |
| 99 | 99 |
return tree_value; |
| 100 | 100 |
} |
| 101 | 101 |
|
| 102 | 102 |
|
| 103 | 103 |
template <typename Sequence> |
| 104 | 104 |
struct PairComp {
|
| 105 | 105 |
typedef typename Sequence::value_type Value; |
| 106 | 106 |
bool operator()(const Value& left, const Value& right) {
|
| 107 | 107 |
return left.second < right.second; |
| 108 | 108 |
} |
| 109 | 109 |
}; |
| 110 | 110 |
|
| 111 | 111 |
template <typename In, typename Enable = void> |
| 112 | 112 |
struct SequenceInputIndicator {
|
| 113 | 113 |
static const bool value = false; |
| 114 | 114 |
}; |
| 115 | 115 |
|
| 116 | 116 |
template <typename In> |
| 117 | 117 |
struct SequenceInputIndicator<In, |
| 118 | 118 |
typename exists<typename In::value_type::first_type>::type> {
|
| 119 | 119 |
static const bool value = true; |
| 120 | 120 |
}; |
| 121 | 121 |
|
| 122 | 122 |
template <typename In, typename Enable = void> |
| 123 | 123 |
struct MapInputIndicator {
|
| 124 | 124 |
static const bool value = false; |
| 125 | 125 |
}; |
| 126 | 126 |
|
| 127 | 127 |
template <typename In> |
| 128 | 128 |
struct MapInputIndicator<In, |
| 129 | 129 |
typename exists<typename In::Value>::type> {
|
| 130 | 130 |
static const bool value = true; |
| 131 | 131 |
}; |
| 132 | 132 |
|
| 133 | 133 |
template <typename In, typename Enable = void> |
| 134 | 134 |
struct SequenceOutputIndicator {
|
| 135 | 135 |
static const bool value = false; |
| 136 | 136 |
}; |
| 137 | 137 |
|
| 138 | 138 |
template <typename Out> |
| 139 | 139 |
struct SequenceOutputIndicator<Out, |
| 140 | 140 |
typename exists<typename Out::value_type>::type> {
|
| 141 | 141 |
static const bool value = true; |
| 142 | 142 |
}; |
| 143 | 143 |
|
| 144 | 144 |
template <typename Out, typename Enable = void> |
| 145 | 145 |
struct MapOutputIndicator {
|
| 146 | 146 |
static const bool value = false; |
| 147 | 147 |
}; |
| 148 | 148 |
|
| 149 | 149 |
template <typename Out> |
| 150 | 150 |
struct MapOutputIndicator<Out, |
| 151 | 151 |
typename exists<typename Out::Value>::type> {
|
| 152 | 152 |
static const bool value = true; |
| 153 | 153 |
}; |
| 154 | 154 |
|
| 155 | 155 |
template <typename In, typename InEnable = void> |
| 156 | 156 |
struct KruskalValueSelector {};
|
| 157 | 157 |
|
| 158 | 158 |
template <typename In> |
| 159 | 159 |
struct KruskalValueSelector<In, |
| 160 | 160 |
typename enable_if<SequenceInputIndicator<In>, void>::type> |
| 161 | 161 |
{
|
| 162 | 162 |
typedef typename In::value_type::second_type Value; |
| 163 | 163 |
}; |
| 164 | 164 |
|
| 165 | 165 |
template <typename In> |
| 166 | 166 |
struct KruskalValueSelector<In, |
| 167 | 167 |
typename enable_if<MapInputIndicator<In>, void>::type> |
| 168 | 168 |
{
|
| 169 | 169 |
typedef typename In::Value Value; |
| 170 | 170 |
}; |
| 171 | 171 |
|
| 172 | 172 |
template <typename Graph, typename In, typename Out, |
| 173 | 173 |
typename InEnable = void> |
| 174 | 174 |
struct KruskalInputSelector {};
|
| 175 | 175 |
|
| 176 | 176 |
template <typename Graph, typename In, typename Out, |
| 177 | 177 |
typename InEnable = void> |
| 178 | 178 |
struct KruskalOutputSelector {};
|
| 179 | 179 |
|
| 180 | 180 |
template <typename Graph, typename In, typename Out> |
| 181 | 181 |
struct KruskalInputSelector<Graph, In, Out, |
| 182 | 182 |
typename enable_if<SequenceInputIndicator<In>, void>::type > |
| 183 | 183 |
{
|
| 184 | 184 |
typedef typename In::value_type::second_type Value; |
| 185 | 185 |
|
| 186 | 186 |
static Value kruskal(const Graph& graph, const In& in, Out& out) {
|
| 187 | 187 |
return KruskalOutputSelector<Graph, In, Out>:: |
| 188 | 188 |
kruskal(graph, in, out); |
| 189 | 189 |
} |
| 190 | 190 |
|
| 191 | 191 |
}; |
| 192 | 192 |
|
| 193 | 193 |
template <typename Graph, typename In, typename Out> |
| 194 | 194 |
struct KruskalInputSelector<Graph, In, Out, |
| 195 | 195 |
typename enable_if<MapInputIndicator<In>, void>::type > |
| 196 | 196 |
{
|
| 197 | 197 |
typedef typename In::Value Value; |
| 198 | 198 |
static Value kruskal(const Graph& graph, const In& in, Out& out) {
|
| 199 | 199 |
typedef typename In::Key MapArc; |
| 200 | 200 |
typedef typename In::Value Value; |
| 201 | 201 |
typedef typename ItemSetTraits<Graph, MapArc>::ItemIt MapArcIt; |
| 202 | 202 |
typedef std::vector<std::pair<MapArc, Value> > Sequence; |
| 203 | 203 |
Sequence seq; |
| 204 | 204 |
|
| 205 | 205 |
for (MapArcIt it(graph); it != INVALID; ++it) {
|
| 206 | 206 |
seq.push_back(std::make_pair(it, in[it])); |
| 207 | 207 |
} |
| 208 | 208 |
|
| 209 | 209 |
std::sort(seq.begin(), seq.end(), PairComp<Sequence>()); |
| 210 | 210 |
return KruskalOutputSelector<Graph, Sequence, Out>:: |
| 211 | 211 |
kruskal(graph, seq, out); |
| 212 | 212 |
} |
| 213 | 213 |
}; |
| 214 | 214 |
|
| 215 | 215 |
template <typename T> |
| 216 | 216 |
struct RemoveConst {
|
| 217 | 217 |
typedef T type; |
| 218 | 218 |
}; |
| 219 | 219 |
|
| 220 | 220 |
template <typename T> |
| 221 | 221 |
struct RemoveConst<const T> {
|
| 222 | 222 |
typedef T type; |
| 223 | 223 |
}; |
| 224 | 224 |
|
| 225 | 225 |
template <typename Graph, typename In, typename Out> |
| 226 | 226 |
struct KruskalOutputSelector<Graph, In, Out, |
| 227 | 227 |
typename enable_if<SequenceOutputIndicator<Out>, void>::type > |
| 228 | 228 |
{
|
| 229 | 229 |
typedef typename In::value_type::second_type Value; |
| 230 | 230 |
|
| 231 | 231 |
static Value kruskal(const Graph& graph, const In& in, Out& out) {
|
| 232 |
typedef |
|
| 232 |
typedef LoggerBoolMap<typename RemoveConst<Out>::type> Map; |
|
| 233 | 233 |
Map map(out); |
| 234 | 234 |
return _kruskal_bits::kruskal(graph, in, map); |
| 235 | 235 |
} |
| 236 | 236 |
|
| 237 | 237 |
}; |
| 238 | 238 |
|
| 239 | 239 |
template <typename Graph, typename In, typename Out> |
| 240 | 240 |
struct KruskalOutputSelector<Graph, In, Out, |
| 241 | 241 |
typename enable_if<MapOutputIndicator<Out>, void>::type > |
| 242 | 242 |
{
|
| 243 | 243 |
typedef typename In::value_type::second_type Value; |
| 244 | 244 |
|
| 245 | 245 |
static Value kruskal(const Graph& graph, const In& in, Out& out) {
|
| 246 | 246 |
return _kruskal_bits::kruskal(graph, in, out); |
| 247 | 247 |
} |
| 248 | 248 |
}; |
| 249 | 249 |
|
| 250 | 250 |
} |
| 251 | 251 |
|
| 252 | 252 |
/// \ingroup spantree |
| 253 | 253 |
/// |
| 254 | 254 |
/// \brief Kruskal's algorithm to find a minimum cost tree of a graph. |
| 255 | 255 |
/// |
| 256 | 256 |
/// This function runs Kruskal's algorithm to find a minimum cost tree. |
| 257 | 257 |
/// Due to some C++ hacking, it accepts various input and output types. |
| 258 | 258 |
/// |
| 259 | 259 |
/// \param g The graph the algorithm runs on. |
| 260 | 260 |
/// It can be either \ref concepts::Digraph "directed" or |
| 261 | 261 |
/// \ref concepts::Graph "undirected". |
| 262 | 262 |
/// If the graph is directed, the algorithm consider it to be |
| 263 | 263 |
/// undirected by disregarding the direction of the arcs. |
| 264 | 264 |
/// |
| 265 | 265 |
/// \param in This object is used to describe the arc costs. It can be one |
| 266 | 266 |
/// of the following choices. |
| 267 | 267 |
/// - An STL compatible 'Forward Container' with |
| 268 | 268 |
/// <tt>std::pair<GR::Edge,X></tt> or |
| 269 | 269 |
/// <tt>std::pair<GR::Arc,X></tt> as its <tt>value_type</tt>, where |
| 270 | 270 |
/// \c X is the type of the costs. The pairs indicates the arcs |
| 271 | 271 |
/// along with the assigned cost. <em>They must be in a |
| 272 | 272 |
/// cost-ascending order.</em> |
| 273 | 273 |
/// - Any readable Arc map. The values of the map indicate the arc costs. |
| 274 | 274 |
/// |
| 275 | 275 |
/// \retval out Here we also have a choise. |
| 276 | 276 |
/// - It can be a writable \c bool arc map. After running the |
| 277 | 277 |
/// algorithm this will contain the found minimum cost spanning |
| 278 | 278 |
/// tree: the value of an arc will be set to \c true if it belongs |
| 279 | 279 |
/// to the tree, otherwise it will be set to \c false. The value of |
| 280 | 280 |
/// each arc will be set exactly once. |
| 281 | 281 |
/// - It can also be an iteraror of an STL Container with |
| 282 | 282 |
/// <tt>GR::Edge</tt> or <tt>GR::Arc</tt> as its |
| 283 | 283 |
/// <tt>value_type</tt>. The algorithm copies the elements of the |
| 284 | 284 |
/// found tree into this sequence. For example, if we know that the |
| 285 | 285 |
/// spanning tree of the graph \c g has say 53 arcs, then we can |
| 286 | 286 |
/// put its arcs into an STL vector \c tree with a code like this. |
| 287 | 287 |
///\code |
| 288 | 288 |
/// std::vector<Arc> tree(53); |
| 289 | 289 |
/// kruskal(g,cost,tree.begin()); |
| 290 | 290 |
///\endcode |
| 291 | 291 |
/// Or if we don't know in advance the size of the tree, we can |
| 292 | 292 |
/// write this. |
| 293 | 293 |
///\code std::vector<Arc> tree; |
| 294 | 294 |
/// kruskal(g,cost,std::back_inserter(tree)); |
| 295 | 295 |
///\endcode |
| 296 | 296 |
/// |
| 297 | 297 |
/// \return The total cost of the found tree. |
| 298 | 298 |
/// |
| 299 | 299 |
/// \warning If kruskal runs on an be consistent of using the same |
| 300 | 300 |
/// Arc type for input and output. |
| 301 | 301 |
/// |
| 302 | 302 |
|
| 303 | 303 |
#ifdef DOXYGEN |
| 304 | 304 |
template <class Graph, class In, class Out> |
| 305 | 305 |
Value kruskal(GR const& g, const In& in, Out& out) |
| 306 | 306 |
#else |
| 307 | 307 |
template <class Graph, class In, class Out> |
| 308 | 308 |
inline typename _kruskal_bits::KruskalValueSelector<In>::Value |
| 309 | 309 |
kruskal(const Graph& graph, const In& in, Out& out) |
| 310 | 310 |
#endif |
| 311 | 311 |
{
|
| 312 | 312 |
return _kruskal_bits::KruskalInputSelector<Graph, In, Out>:: |
| 313 | 313 |
kruskal(graph, in, out); |
| 314 | 314 |
} |
| 315 | 315 |
|
| 316 | 316 |
|
| 317 | 317 |
|
| 318 | 318 |
|
| 319 | 319 |
template <class Graph, class In, class Out> |
| 320 | 320 |
inline typename _kruskal_bits::KruskalValueSelector<In>::Value |
| 321 | 321 |
kruskal(const Graph& graph, const In& in, const Out& out) |
| 322 | 322 |
{
|
| 323 | 323 |
return _kruskal_bits::KruskalInputSelector<Graph, In, const Out>:: |
| 324 | 324 |
kruskal(graph, in, out); |
| 325 | 325 |
} |
| 326 | 326 |
|
| 327 | 327 |
} //namespace lemon |
| 328 | 328 |
|
| 329 | 329 |
#endif //LEMON_KRUSKAL_H |
| ... | ... |
@@ -1511,276 +1511,276 @@ |
| 1511 | 1511 |
class NotMap : public MapBase<typename M::Key, bool> {
|
| 1512 | 1512 |
const M &_m; |
| 1513 | 1513 |
public: |
| 1514 | 1514 |
typedef MapBase<typename M::Key, bool> Parent; |
| 1515 | 1515 |
typedef typename Parent::Key Key; |
| 1516 | 1516 |
typedef typename Parent::Value Value; |
| 1517 | 1517 |
|
| 1518 | 1518 |
/// Constructor |
| 1519 | 1519 |
NotMap(const M &m) : _m(m) {}
|
| 1520 | 1520 |
/// \e |
| 1521 | 1521 |
Value operator[](const Key &k) const { return !_m[k]; }
|
| 1522 | 1522 |
}; |
| 1523 | 1523 |
|
| 1524 | 1524 |
/// Logical 'not' of a map (read-write version) |
| 1525 | 1525 |
|
| 1526 | 1526 |
/// This \ref concepts::ReadWriteMap "read-write map" returns the |
| 1527 | 1527 |
/// logical negation of the values of the given map. |
| 1528 | 1528 |
/// Its \c Key is inherited from \c M and its \c Value is \c bool. |
| 1529 | 1529 |
/// It makes also possible to write the map. When a value is set, |
| 1530 | 1530 |
/// the opposite value is set to the original map. |
| 1531 | 1531 |
/// |
| 1532 | 1532 |
/// The simplest way of using this map is through the notWriteMap() |
| 1533 | 1533 |
/// function. |
| 1534 | 1534 |
/// |
| 1535 | 1535 |
/// \sa NotMap |
| 1536 | 1536 |
template <typename M> |
| 1537 | 1537 |
class NotWriteMap : public MapBase<typename M::Key, bool> {
|
| 1538 | 1538 |
M &_m; |
| 1539 | 1539 |
public: |
| 1540 | 1540 |
typedef MapBase<typename M::Key, bool> Parent; |
| 1541 | 1541 |
typedef typename Parent::Key Key; |
| 1542 | 1542 |
typedef typename Parent::Value Value; |
| 1543 | 1543 |
|
| 1544 | 1544 |
/// Constructor |
| 1545 | 1545 |
NotWriteMap(M &m) : _m(m) {}
|
| 1546 | 1546 |
/// \e |
| 1547 | 1547 |
Value operator[](const Key &k) const { return !_m[k]; }
|
| 1548 | 1548 |
/// \e |
| 1549 | 1549 |
void set(const Key &k, bool v) { _m.set(k, !v); }
|
| 1550 | 1550 |
}; |
| 1551 | 1551 |
|
| 1552 | 1552 |
/// Returns a \ref NotMap class |
| 1553 | 1553 |
|
| 1554 | 1554 |
/// This function just returns a \ref NotMap class. |
| 1555 | 1555 |
/// |
| 1556 | 1556 |
/// For example, if \c m is a map with \c bool values, then |
| 1557 | 1557 |
/// <tt>notMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>. |
| 1558 | 1558 |
/// |
| 1559 | 1559 |
/// \relates NotMap |
| 1560 | 1560 |
template <typename M> |
| 1561 | 1561 |
inline NotMap<M> notMap(const M &m) {
|
| 1562 | 1562 |
return NotMap<M>(m); |
| 1563 | 1563 |
} |
| 1564 | 1564 |
|
| 1565 | 1565 |
/// Returns a \ref NotWriteMap class |
| 1566 | 1566 |
|
| 1567 | 1567 |
/// This function just returns a \ref NotWriteMap class. |
| 1568 | 1568 |
/// |
| 1569 | 1569 |
/// For example, if \c m is a map with \c bool values, then |
| 1570 | 1570 |
/// <tt>notWriteMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>. |
| 1571 | 1571 |
/// Moreover it makes also possible to write the map. |
| 1572 | 1572 |
/// |
| 1573 | 1573 |
/// \relates NotWriteMap |
| 1574 | 1574 |
template <typename M> |
| 1575 | 1575 |
inline NotWriteMap<M> notWriteMap(M &m) {
|
| 1576 | 1576 |
return NotWriteMap<M>(m); |
| 1577 | 1577 |
} |
| 1578 | 1578 |
|
| 1579 | 1579 |
|
| 1580 | 1580 |
/// Combination of two maps using the \c == operator |
| 1581 | 1581 |
|
| 1582 | 1582 |
/// This \ref concepts::ReadMap "read-only map" assigns \c true to |
| 1583 | 1583 |
/// the keys for which the corresponding values of the two maps are |
| 1584 | 1584 |
/// equal. |
| 1585 | 1585 |
/// Its \c Key type is inherited from \c M1 and its \c Value type is |
| 1586 | 1586 |
/// \c bool. \c M2::Key must be convertible to \c M1::Key. |
| 1587 | 1587 |
/// |
| 1588 | 1588 |
/// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for |
| 1589 | 1589 |
/// \code |
| 1590 | 1590 |
/// EqualMap<M1,M2> em(m1,m2); |
| 1591 | 1591 |
/// \endcode |
| 1592 | 1592 |
/// <tt>em[x]</tt> will be equal to <tt>m1[x]==m2[x]</tt>. |
| 1593 | 1593 |
/// |
| 1594 | 1594 |
/// The simplest way of using this map is through the equalMap() |
| 1595 | 1595 |
/// function. |
| 1596 | 1596 |
/// |
| 1597 | 1597 |
/// \sa LessMap |
| 1598 | 1598 |
template<typename M1, typename M2> |
| 1599 | 1599 |
class EqualMap : public MapBase<typename M1::Key, bool> {
|
| 1600 | 1600 |
const M1 &_m1; |
| 1601 | 1601 |
const M2 &_m2; |
| 1602 | 1602 |
public: |
| 1603 | 1603 |
typedef MapBase<typename M1::Key, bool> Parent; |
| 1604 | 1604 |
typedef typename Parent::Key Key; |
| 1605 | 1605 |
typedef typename Parent::Value Value; |
| 1606 | 1606 |
|
| 1607 | 1607 |
/// Constructor |
| 1608 | 1608 |
EqualMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
|
| 1609 | 1609 |
/// \e |
| 1610 | 1610 |
Value operator[](const Key &k) const { return _m1[k]==_m2[k]; }
|
| 1611 | 1611 |
}; |
| 1612 | 1612 |
|
| 1613 | 1613 |
/// Returns an \ref EqualMap class |
| 1614 | 1614 |
|
| 1615 | 1615 |
/// This function just returns an \ref EqualMap class. |
| 1616 | 1616 |
/// |
| 1617 | 1617 |
/// For example, if \c m1 and \c m2 are maps with keys and values of |
| 1618 | 1618 |
/// the same type, then <tt>equalMap(m1,m2)[x]</tt> will be equal to |
| 1619 | 1619 |
/// <tt>m1[x]==m2[x]</tt>. |
| 1620 | 1620 |
/// |
| 1621 | 1621 |
/// \relates EqualMap |
| 1622 | 1622 |
template<typename M1, typename M2> |
| 1623 | 1623 |
inline EqualMap<M1, M2> equalMap(const M1 &m1, const M2 &m2) {
|
| 1624 | 1624 |
return EqualMap<M1, M2>(m1,m2); |
| 1625 | 1625 |
} |
| 1626 | 1626 |
|
| 1627 | 1627 |
|
| 1628 | 1628 |
/// Combination of two maps using the \c < operator |
| 1629 | 1629 |
|
| 1630 | 1630 |
/// This \ref concepts::ReadMap "read-only map" assigns \c true to |
| 1631 | 1631 |
/// the keys for which the corresponding value of the first map is |
| 1632 | 1632 |
/// less then the value of the second map. |
| 1633 | 1633 |
/// Its \c Key type is inherited from \c M1 and its \c Value type is |
| 1634 | 1634 |
/// \c bool. \c M2::Key must be convertible to \c M1::Key. |
| 1635 | 1635 |
/// |
| 1636 | 1636 |
/// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for |
| 1637 | 1637 |
/// \code |
| 1638 | 1638 |
/// LessMap<M1,M2> lm(m1,m2); |
| 1639 | 1639 |
/// \endcode |
| 1640 | 1640 |
/// <tt>lm[x]</tt> will be equal to <tt>m1[x]<m2[x]</tt>. |
| 1641 | 1641 |
/// |
| 1642 | 1642 |
/// The simplest way of using this map is through the lessMap() |
| 1643 | 1643 |
/// function. |
| 1644 | 1644 |
/// |
| 1645 | 1645 |
/// \sa EqualMap |
| 1646 | 1646 |
template<typename M1, typename M2> |
| 1647 | 1647 |
class LessMap : public MapBase<typename M1::Key, bool> {
|
| 1648 | 1648 |
const M1 &_m1; |
| 1649 | 1649 |
const M2 &_m2; |
| 1650 | 1650 |
public: |
| 1651 | 1651 |
typedef MapBase<typename M1::Key, bool> Parent; |
| 1652 | 1652 |
typedef typename Parent::Key Key; |
| 1653 | 1653 |
typedef typename Parent::Value Value; |
| 1654 | 1654 |
|
| 1655 | 1655 |
/// Constructor |
| 1656 | 1656 |
LessMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
|
| 1657 | 1657 |
/// \e |
| 1658 | 1658 |
Value operator[](const Key &k) const { return _m1[k]<_m2[k]; }
|
| 1659 | 1659 |
}; |
| 1660 | 1660 |
|
| 1661 | 1661 |
/// Returns an \ref LessMap class |
| 1662 | 1662 |
|
| 1663 | 1663 |
/// This function just returns an \ref LessMap class. |
| 1664 | 1664 |
/// |
| 1665 | 1665 |
/// For example, if \c m1 and \c m2 are maps with keys and values of |
| 1666 | 1666 |
/// the same type, then <tt>lessMap(m1,m2)[x]</tt> will be equal to |
| 1667 | 1667 |
/// <tt>m1[x]<m2[x]</tt>. |
| 1668 | 1668 |
/// |
| 1669 | 1669 |
/// \relates LessMap |
| 1670 | 1670 |
template<typename M1, typename M2> |
| 1671 | 1671 |
inline LessMap<M1, M2> lessMap(const M1 &m1, const M2 &m2) {
|
| 1672 | 1672 |
return LessMap<M1, M2>(m1,m2); |
| 1673 | 1673 |
} |
| 1674 | 1674 |
|
| 1675 | 1675 |
namespace _maps_bits {
|
| 1676 | 1676 |
|
| 1677 | 1677 |
template <typename _Iterator, typename Enable = void> |
| 1678 | 1678 |
struct IteratorTraits {
|
| 1679 | 1679 |
typedef typename std::iterator_traits<_Iterator>::value_type Value; |
| 1680 | 1680 |
}; |
| 1681 | 1681 |
|
| 1682 | 1682 |
template <typename _Iterator> |
| 1683 | 1683 |
struct IteratorTraits<_Iterator, |
| 1684 | 1684 |
typename exists<typename _Iterator::container_type>::type> |
| 1685 | 1685 |
{
|
| 1686 | 1686 |
typedef typename _Iterator::container_type::value_type Value; |
| 1687 | 1687 |
}; |
| 1688 | 1688 |
|
| 1689 | 1689 |
} |
| 1690 | 1690 |
|
| 1691 | 1691 |
/// \brief Writable bool map for logging each \c true assigned element |
| 1692 | 1692 |
/// |
| 1693 | 1693 |
/// A \ref concepts::WriteMap "writable" bool map for logging |
| 1694 | 1694 |
/// each \c true assigned element, i.e it copies subsequently each |
| 1695 | 1695 |
/// keys set to \c true to the given iterator. |
| 1696 | 1696 |
/// The most important usage of it is storing certain nodes or arcs |
| 1697 | 1697 |
/// that were marked \c true by an algorithm. |
| 1698 | 1698 |
/// |
| 1699 | 1699 |
/// There are several algorithms that provide solutions through bool |
| 1700 | 1700 |
/// maps and most of them assign \c true at most once for each key. |
| 1701 | 1701 |
/// In these cases it is a natural request to store each \c true |
| 1702 | 1702 |
/// assigned elements (in order of the assignment), which can be |
| 1703 |
/// easily done with |
|
| 1703 |
/// easily done with LoggerBoolMap. |
|
| 1704 | 1704 |
/// |
| 1705 |
/// The simplest way of using this map is through the |
|
| 1705 |
/// The simplest way of using this map is through the loggerBoolMap() |
|
| 1706 | 1706 |
/// function. |
| 1707 | 1707 |
/// |
| 1708 | 1708 |
/// \tparam It The type of the iterator. |
| 1709 | 1709 |
/// \tparam Ke The key type of the map. The default value set |
| 1710 | 1710 |
/// according to the iterator type should work in most cases. |
| 1711 | 1711 |
/// |
| 1712 | 1712 |
/// \note The container of the iterator must contain enough space |
| 1713 | 1713 |
/// for the elements or the iterator should be an inserter iterator. |
| 1714 | 1714 |
#ifdef DOXYGEN |
| 1715 | 1715 |
template <typename It, typename Ke> |
| 1716 | 1716 |
#else |
| 1717 | 1717 |
template <typename It, |
| 1718 | 1718 |
typename Ke=typename _maps_bits::IteratorTraits<It>::Value> |
| 1719 | 1719 |
#endif |
| 1720 |
class |
|
| 1720 |
class LoggerBoolMap {
|
|
| 1721 | 1721 |
public: |
| 1722 | 1722 |
typedef It Iterator; |
| 1723 | 1723 |
|
| 1724 | 1724 |
typedef Ke Key; |
| 1725 | 1725 |
typedef bool Value; |
| 1726 | 1726 |
|
| 1727 | 1727 |
/// Constructor |
| 1728 |
|
|
| 1728 |
LoggerBoolMap(Iterator it) |
|
| 1729 | 1729 |
: _begin(it), _end(it) {}
|
| 1730 | 1730 |
|
| 1731 | 1731 |
/// Gives back the given iterator set for the first key |
| 1732 | 1732 |
Iterator begin() const {
|
| 1733 | 1733 |
return _begin; |
| 1734 | 1734 |
} |
| 1735 | 1735 |
|
| 1736 | 1736 |
/// Gives back the the 'after the last' iterator |
| 1737 | 1737 |
Iterator end() const {
|
| 1738 | 1738 |
return _end; |
| 1739 | 1739 |
} |
| 1740 | 1740 |
|
| 1741 | 1741 |
/// The set function of the map |
| 1742 | 1742 |
void set(const Key& key, Value value) {
|
| 1743 | 1743 |
if (value) {
|
| 1744 | 1744 |
*_end++ = key; |
| 1745 | 1745 |
} |
| 1746 | 1746 |
} |
| 1747 | 1747 |
|
| 1748 | 1748 |
private: |
| 1749 | 1749 |
Iterator _begin; |
| 1750 | 1750 |
Iterator _end; |
| 1751 | 1751 |
}; |
| 1752 | 1752 |
|
| 1753 |
/// Returns a \ref |
|
| 1753 |
/// Returns a \ref LoggerBoolMap class |
|
| 1754 | 1754 |
|
| 1755 |
/// This function just returns a \ref |
|
| 1755 |
/// This function just returns a \ref LoggerBoolMap class. |
|
| 1756 | 1756 |
/// |
| 1757 | 1757 |
/// The most important usage of it is storing certain nodes or arcs |
| 1758 | 1758 |
/// that were marked \c true by an algorithm. |
| 1759 | 1759 |
/// For example it makes easier to store the nodes in the processing |
| 1760 | 1760 |
/// order of Dfs algorithm, as the following examples show. |
| 1761 | 1761 |
/// \code |
| 1762 | 1762 |
/// std::vector<Node> v; |
| 1763 |
/// dfs(g,s).processedMap( |
|
| 1763 |
/// dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run(); |
|
| 1764 | 1764 |
/// \endcode |
| 1765 | 1765 |
/// \code |
| 1766 | 1766 |
/// std::vector<Node> v(countNodes(g)); |
| 1767 |
/// dfs(g,s).processedMap( |
|
| 1767 |
/// dfs(g,s).processedMap(loggerBoolMap(v.begin())).run(); |
|
| 1768 | 1768 |
/// \endcode |
| 1769 | 1769 |
/// |
| 1770 | 1770 |
/// \note The container of the iterator must contain enough space |
| 1771 | 1771 |
/// for the elements or the iterator should be an inserter iterator. |
| 1772 | 1772 |
/// |
| 1773 |
/// \note |
|
| 1773 |
/// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so |
|
| 1774 | 1774 |
/// it cannot be used when a readable map is needed, for example as |
| 1775 |
/// \c ReachedMap for Bfs, Dfs and Dijkstra algorithms. |
|
| 1775 |
/// \c ReachedMap for \ref Bfs, \ref Dfs and \ref Dijkstra algorithms. |
|
| 1776 | 1776 |
/// |
| 1777 |
/// \relates |
|
| 1777 |
/// \relates LoggerBoolMap |
|
| 1778 | 1778 |
template<typename Iterator> |
| 1779 |
inline StoreBoolMap<Iterator> storeBoolMap(Iterator it) {
|
|
| 1780 |
return StoreBoolMap<Iterator>(it); |
|
| 1779 |
inline LoggerBoolMap<Iterator> loggerBoolMap(Iterator it) {
|
|
| 1780 |
return LoggerBoolMap<Iterator>(it); |
|
| 1781 | 1781 |
} |
| 1782 | 1782 |
|
| 1783 | 1783 |
/// @} |
| 1784 | 1784 |
} |
| 1785 | 1785 |
|
| 1786 | 1786 |
#endif // LEMON_MAPS_H |
| ... | ... |
@@ -116,216 +116,216 @@ |
| 116 | 116 |
checkConcept<ReadMap<double,double>, IdentityMap<double> >(); |
| 117 | 117 |
check(identityMap<double>()[1.0] == 1.0 && identityMap<double>()[3.14] == 3.14, |
| 118 | 118 |
"Something is wrong with IdentityMap"); |
| 119 | 119 |
} |
| 120 | 120 |
|
| 121 | 121 |
// RangeMap |
| 122 | 122 |
{
|
| 123 | 123 |
checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >(); |
| 124 | 124 |
RangeMap<B> map1; |
| 125 | 125 |
RangeMap<B> map2(10); |
| 126 | 126 |
RangeMap<B> map3(10,B()); |
| 127 | 127 |
RangeMap<B> map4 = map1; |
| 128 | 128 |
RangeMap<B> map5 = rangeMap<B>(); |
| 129 | 129 |
RangeMap<B> map6 = rangeMap<B>(10); |
| 130 | 130 |
RangeMap<B> map7 = rangeMap(10,B()); |
| 131 | 131 |
|
| 132 | 132 |
checkConcept< ReferenceMap<int, double, double&, const double&>, |
| 133 | 133 |
RangeMap<double> >(); |
| 134 | 134 |
std::vector<double> v(10, 0); |
| 135 | 135 |
v[5] = 100; |
| 136 | 136 |
RangeMap<double> map8(v); |
| 137 | 137 |
RangeMap<double> map9 = rangeMap(v); |
| 138 | 138 |
check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100, |
| 139 | 139 |
"Something is wrong with RangeMap"); |
| 140 | 140 |
} |
| 141 | 141 |
|
| 142 | 142 |
// SparseMap |
| 143 | 143 |
{
|
| 144 | 144 |
checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >(); |
| 145 | 145 |
SparseMap<A,B> map1; |
| 146 | 146 |
SparseMap<A,B> map2 = B(); |
| 147 | 147 |
SparseMap<A,B> map3 = sparseMap<A,B>(); |
| 148 | 148 |
SparseMap<A,B> map4 = sparseMap<A>(B()); |
| 149 | 149 |
|
| 150 | 150 |
checkConcept< ReferenceMap<double, int, int&, const int&>, |
| 151 | 151 |
SparseMap<double, int> >(); |
| 152 | 152 |
std::map<double, int> m; |
| 153 | 153 |
SparseMap<double, int> map5(m); |
| 154 | 154 |
SparseMap<double, int> map6(m,10); |
| 155 | 155 |
SparseMap<double, int> map7 = sparseMap(m); |
| 156 | 156 |
SparseMap<double, int> map8 = sparseMap(m,10); |
| 157 | 157 |
|
| 158 | 158 |
check(map5[1.0] == 0 && map5[3.14] == 0 && map6[1.0] == 10 && map6[3.14] == 10, |
| 159 | 159 |
"Something is wrong with SparseMap"); |
| 160 | 160 |
map5[1.0] = map6[3.14] = 100; |
| 161 | 161 |
check(map5[1.0] == 100 && map5[3.14] == 0 && map6[1.0] == 10 && map6[3.14] == 100, |
| 162 | 162 |
"Something is wrong with SparseMap"); |
| 163 | 163 |
} |
| 164 | 164 |
|
| 165 | 165 |
// ComposeMap |
| 166 | 166 |
{
|
| 167 | 167 |
typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap; |
| 168 | 168 |
checkConcept<ReadMap<B,double>, CompMap>(); |
| 169 | 169 |
CompMap map1(DoubleMap(),ReadMap<B,A>()); |
| 170 | 170 |
CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>()); |
| 171 | 171 |
|
| 172 | 172 |
SparseMap<double, bool> m1(false); m1[3.14] = true; |
| 173 | 173 |
RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14; |
| 174 | 174 |
check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1], "Something is wrong with ComposeMap") |
| 175 | 175 |
} |
| 176 | 176 |
|
| 177 | 177 |
// CombineMap |
| 178 | 178 |
{
|
| 179 | 179 |
typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap; |
| 180 | 180 |
checkConcept<ReadMap<A,double>, CombMap>(); |
| 181 | 181 |
CombMap map1(DoubleMap(), DoubleMap()); |
| 182 | 182 |
CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>()); |
| 183 | 183 |
|
| 184 | 184 |
check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3, |
| 185 | 185 |
"Something is wrong with CombineMap"); |
| 186 | 186 |
} |
| 187 | 187 |
|
| 188 | 188 |
// FunctorToMap, MapToFunctor |
| 189 | 189 |
{
|
| 190 | 190 |
checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >(); |
| 191 | 191 |
checkConcept<ReadMap<A,B>, FunctorToMap<F> >(); |
| 192 | 192 |
FunctorToMap<F> map1; |
| 193 | 193 |
FunctorToMap<F> map2(F()); |
| 194 | 194 |
B b = functorToMap(F())[A()]; |
| 195 | 195 |
|
| 196 | 196 |
checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >(); |
| 197 | 197 |
MapToFunctor<ReadMap<A,B> > map(ReadMap<A,B>()); |
| 198 | 198 |
|
| 199 | 199 |
check(functorToMap(&func)[A()] == 3, "Something is wrong with FunctorToMap"); |
| 200 | 200 |
check(mapToFunctor(constMap<A,int>(2))(A()) == 2, "Something is wrong with MapToFunctor"); |
| 201 | 201 |
check(mapToFunctor(functorToMap(&func))(A()) == 3 && mapToFunctor(functorToMap(&func))[A()] == 3, |
| 202 | 202 |
"Something is wrong with FunctorToMap or MapToFunctor"); |
| 203 | 203 |
check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2, |
| 204 | 204 |
"Something is wrong with FunctorToMap or MapToFunctor"); |
| 205 | 205 |
} |
| 206 | 206 |
|
| 207 | 207 |
// ConvertMap |
| 208 | 208 |
{
|
| 209 | 209 |
checkConcept<ReadMap<double,double>, ConvertMap<ReadMap<double, int>, double> >(); |
| 210 | 210 |
ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true)); |
| 211 | 211 |
ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false)); |
| 212 | 212 |
} |
| 213 | 213 |
|
| 214 | 214 |
// ForkMap |
| 215 | 215 |
{
|
| 216 | 216 |
checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >(); |
| 217 | 217 |
|
| 218 | 218 |
typedef RangeMap<double> RM; |
| 219 | 219 |
typedef SparseMap<int, double> SM; |
| 220 | 220 |
RM m1(10, -1); |
| 221 | 221 |
SM m2(-1); |
| 222 | 222 |
checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >(); |
| 223 | 223 |
checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >(); |
| 224 | 224 |
ForkMap<RM, SM> map1(m1,m2); |
| 225 | 225 |
ForkMap<SM, RM> map2 = forkMap(m2,m1); |
| 226 | 226 |
map2.set(5, 10); |
| 227 | 227 |
check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 && m2[5] == 10 && map2[1] == -1 && map2[5] == 10, |
| 228 | 228 |
"Something is wrong with ForkMap"); |
| 229 | 229 |
} |
| 230 | 230 |
|
| 231 | 231 |
// Arithmetic maps: |
| 232 | 232 |
// - AddMap, SubMap, MulMap, DivMap |
| 233 | 233 |
// - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap |
| 234 | 234 |
// - NegMap, NegWriteMap, AbsMap |
| 235 | 235 |
{
|
| 236 | 236 |
checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >(); |
| 237 | 237 |
checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >(); |
| 238 | 238 |
checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >(); |
| 239 | 239 |
checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >(); |
| 240 | 240 |
|
| 241 | 241 |
ConstMap<int, double> c1(1.0), c2(3.14); |
| 242 | 242 |
IdentityMap<int> im; |
| 243 | 243 |
ConvertMap<IdentityMap<int>, double> id(im); |
| 244 | 244 |
check(addMap(c1,id)[0] == 1.0 && addMap(c1,id)[10] == 11.0, "Something is wrong with AddMap"); |
| 245 | 245 |
check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0, "Something is wrong with SubMap"); |
| 246 | 246 |
check(mulMap(id,c2)[0] == 0 && mulMap(id,c2)[2] == 6.28, "Something is wrong with MulMap"); |
| 247 | 247 |
check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2] == 1.57, "Something is wrong with DivMap"); |
| 248 | 248 |
|
| 249 | 249 |
checkConcept<DoubleMap, ShiftMap<DoubleMap> >(); |
| 250 | 250 |
checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >(); |
| 251 | 251 |
checkConcept<DoubleMap, ScaleMap<DoubleMap> >(); |
| 252 | 252 |
checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >(); |
| 253 | 253 |
checkConcept<DoubleMap, NegMap<DoubleMap> >(); |
| 254 | 254 |
checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >(); |
| 255 | 255 |
checkConcept<DoubleMap, AbsMap<DoubleMap> >(); |
| 256 | 256 |
|
| 257 | 257 |
check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0, |
| 258 | 258 |
"Something is wrong with ShiftMap"); |
| 259 | 259 |
check(shiftWriteMap(id, 2.0)[1] == 3.0 && shiftWriteMap(id, 2.0)[10] == 12.0, |
| 260 | 260 |
"Something is wrong with ShiftWriteMap"); |
| 261 | 261 |
check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0, |
| 262 | 262 |
"Something is wrong with ScaleMap"); |
| 263 | 263 |
check(scaleWriteMap(id, 2.0)[1] == 2.0 && scaleWriteMap(id, 2.0)[10] == 20.0, |
| 264 | 264 |
"Something is wrong with ScaleWriteMap"); |
| 265 | 265 |
check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0, |
| 266 | 266 |
"Something is wrong with NegMap"); |
| 267 | 267 |
check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0, |
| 268 | 268 |
"Something is wrong with NegWriteMap"); |
| 269 | 269 |
check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0, |
| 270 | 270 |
"Something is wrong with AbsMap"); |
| 271 | 271 |
} |
| 272 | 272 |
|
| 273 | 273 |
// Logical maps: |
| 274 | 274 |
// - TrueMap, FalseMap |
| 275 | 275 |
// - AndMap, OrMap |
| 276 | 276 |
// - NotMap, NotWriteMap |
| 277 | 277 |
// - EqualMap, LessMap |
| 278 | 278 |
{
|
| 279 | 279 |
checkConcept<BoolMap, TrueMap<A> >(); |
| 280 | 280 |
checkConcept<BoolMap, FalseMap<A> >(); |
| 281 | 281 |
checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >(); |
| 282 | 282 |
checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >(); |
| 283 | 283 |
checkConcept<BoolMap, NotMap<BoolMap> >(); |
| 284 | 284 |
checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >(); |
| 285 | 285 |
checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >(); |
| 286 | 286 |
checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >(); |
| 287 | 287 |
|
| 288 | 288 |
TrueMap<int> tm; |
| 289 | 289 |
FalseMap<int> fm; |
| 290 | 290 |
RangeMap<bool> rm(2); |
| 291 | 291 |
rm[0] = true; rm[1] = false; |
| 292 | 292 |
check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] && !andMap(fm,rm)[0] && !andMap(fm,rm)[1], |
| 293 | 293 |
"Something is wrong with AndMap"); |
| 294 | 294 |
check(orMap(tm,rm)[0] && orMap(tm,rm)[1] && orMap(fm,rm)[0] && !orMap(fm,rm)[1], |
| 295 | 295 |
"Something is wrong with OrMap"); |
| 296 | 296 |
check(!notMap(rm)[0] && notMap(rm)[1], "Something is wrong with NotMap"); |
| 297 | 297 |
check(!notWriteMap(rm)[0] && notWriteMap(rm)[1], "Something is wrong with NotWriteMap"); |
| 298 | 298 |
|
| 299 | 299 |
ConstMap<int, double> cm(2.0); |
| 300 | 300 |
IdentityMap<int> im; |
| 301 | 301 |
ConvertMap<IdentityMap<int>, double> id(im); |
| 302 | 302 |
check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3], |
| 303 | 303 |
"Something is wrong with LessMap"); |
| 304 | 304 |
check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3], |
| 305 | 305 |
"Something is wrong with EqualMap"); |
| 306 | 306 |
} |
| 307 | 307 |
|
| 308 |
// |
|
| 308 |
// LoggerBoolMap |
|
| 309 | 309 |
{
|
| 310 | 310 |
typedef std::vector<int> vec; |
| 311 | 311 |
vec v1; |
| 312 | 312 |
vec v2(10); |
| 313 |
StoreBoolMap<std::back_insert_iterator<vec> > map1(std::back_inserter(v1)); |
|
| 314 |
StoreBoolMap<vec::iterator> map2(v2.begin()); |
|
| 313 |
LoggerBoolMap<std::back_insert_iterator<vec> > map1(std::back_inserter(v1)); |
|
| 314 |
LoggerBoolMap<vec::iterator> map2(v2.begin()); |
|
| 315 | 315 |
map1.set(10, false); |
| 316 | 316 |
map1.set(20, true); map2.set(20, true); |
| 317 | 317 |
map1.set(30, false); map2.set(40, false); |
| 318 | 318 |
map1.set(50, true); map2.set(50, true); |
| 319 | 319 |
map1.set(60, true); map2.set(60, true); |
| 320 | 320 |
check(v1.size() == 3 && v2.size() == 10 && |
| 321 | 321 |
v1[0]==20 && v1[1]==50 && v1[2]==60 && v2[0]==20 && v2[1]==50 && v2[2]==60, |
| 322 |
"Something is wrong with |
|
| 322 |
"Something is wrong with LoggerBoolMap"); |
|
| 323 | 323 |
|
| 324 | 324 |
int i = 0; |
| 325 |
for ( |
|
| 325 |
for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin(); |
|
| 326 | 326 |
it != map2.end(); ++it ) |
| 327 |
check(v1[i++] == *it, "Something is wrong with |
|
| 327 |
check(v1[i++] == *it, "Something is wrong with LoggerBoolMap"); |
|
| 328 | 328 |
} |
| 329 | 329 |
|
| 330 | 330 |
return 0; |
| 331 | 331 |
} |
0 comments (0 inline)