Small changes in min. cost flow algorithms.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2007
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #ifndef LEMON_MAP_ITERATOR_H
20 #define LEMON_MAP_ITERATOR_H
22 #include <lemon/bits/traits.h>
23 #include <lemon/bits/utility.h>
27 /// \brief Iterators on the maps.
33 /// \brief Iterator for maps with possibility of changing values.
35 /// Iterator for maps with possibility of changing values.
36 template <typename Graph, typename Item, typename Map>
37 class MapIt : public ItemSetTraits<Graph, Item>::ItemIt {
40 typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
42 typedef typename Map::Value Value;
44 /// \brief Creates an iterator
46 /// Creates an iterator for the map, which iterates on the
47 /// given graph item set.
48 MapIt(const Graph& _graph, Map& _map) : Parent(_graph), map(_map) {}
50 /// \brief Gives back the map's value on the current position.
52 /// Gives back the map's value on the current position.
53 typename MapTraits<Map>::ConstReturnValue operator*() const {
57 /// \brief Gives back a reference to the map's value.
59 /// Gives back a reference to the map's value on the current position.
60 typename MapTraits<Map>::ReturnValue operator*() {
64 /// \brief Sets the value on the current position
66 /// Sets the value on the current position.
67 void set(const Value& value) {
68 map.set(*this, value);
78 /// \brief Iterator for maps with possibility of getting values.
80 /// Iterator for maps with possibility of getting values.
81 template <typename Graph, typename Item, typename Map>
82 class ConstMapIt : public ItemSetTraits<Graph, Item>::ItemIt {
85 typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
87 typedef typename Map::Value Value;
89 /// \brief Creates an iterator
91 /// Creates an iterator for the map, which iterates on the
92 /// given graph item set.
93 ConstMapIt(const Graph& _graph, const Map& _map)
94 : Parent(_graph), map(_map) {}
96 /// \brief Gives back the map's value on the current position.
98 /// Gives back the map's value on the current position.
99 typename MapTraits<Map>::ConstReturnValue operator*() const {
110 /// \brief Iterator for maps which filters items by the values.
112 /// Iterator for maps which gives back only that items which mapped
113 /// to an given value.
114 template <typename Graph, typename Item, typename Map>
116 : public ItemSetTraits<Graph, Item>::ItemIt {
119 typedef typename ItemSetTraits<Graph, Item>::ItemIt Parent;
121 typedef typename Map::Value Value;
123 /// \brief Creates an iterator
125 /// Creates an iterator for the map, which iterates on the
126 /// given graph item set and filters all items which mapped value
127 /// is not equal to the \c _value.
128 FilterMapIt(const Graph& _graph, const Map& _map, const Value& _value)
129 : Parent(_graph), map(_map), value(_value) {}
131 /// \brief Increment operator
133 /// Skips items which has not mapped to the given value.
134 FilterMapIt& operator++() {
135 Parent::operator++();
136 while (*this != INVALID && map[*this] != value) Parent::operator++();