COIN-OR::LEMON - Graph Library

Changeset 1810:474d093466a5 in lemon-0.x


Ignore:
Timestamp:
11/16/05 19:58:10 (18 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2355
Message:

Modified iterators on graph maps
Other iterators for not graph maps

Location:
lemon
Files:
2 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • lemon/bits/array_map.h

    r1719 r1810  
    1919
    2020#include <memory>
    21 #include <lemon/bits/map_iterator.h>
     21#include <lemon/bits/map_extender.h>
    2222#include <lemon/concept_check.h>
    2323#include <lemon/concept/maps.h>
  • lemon/bits/static_map.h

    r1719 r1810  
    2222
    2323#include <lemon/utility.h>
    24 #include <lemon/bits/map_iterator.h>
     24#include <lemon/bits/map_extender.h>
    2525#include <lemon/bits/alteration_notifier.h>
    2626#include <lemon/error.h>
  • lemon/bits/vector_map.h

    r1730 r1810  
    2222
    2323#include <lemon/utility.h>
    24 #include <lemon/bits/map_iterator.h>
     24#include <lemon/bits/map_extender.h>
    2525#include <lemon/bits/alteration_notifier.h>
    2626#include <lemon/concept_check.h>
  • lemon/iterable_maps.h

    r1805 r1810  
    137137    {
    138138      sep=0;
    139       for(typename BaseMap::MapSet::iterator i=cref.mapSet().begin();
    140           i!=cref.mapSet().end();
    141           ++i) {
    142         i->second=sep;
    143         vals.push_back(i->first);
     139      for(typename BaseMap::MapIt i(cref);i!=INVALID; ++i) {
     140        i.set(sep);
     141        vals.push_back(i);
    144142        sep++;
    145143      }
     
    304302    template <typename Item>
    305303    struct IterableIntMapNode {
    306       IterableIntMapNode() : value(-1) {}
     304      IterableIntMapNode() {}
     305      IterableIntMapNode(int _value) : value(_value) {}
    307306      Item prev, next;
    308307      int value;
     
    314313  /// \brief Dynamic iterable integer map.
    315314  ///
    316   /// \todo Document please
     315  /// This class provides a special graph map type which can store
     316  /// for each graph item(node, edge, etc.) an integer value. For each
     317  /// non negative value it is possible to iterate on the keys which
     318  /// mapped to the given value.
     319  ///
     320  /// \param _Graph The graph type.
     321  /// \param _Item One of the graph's item type, the key of the map.
    317322  template <typename _Graph, typename _Item>
    318323  class IterableIntMap : protected ItemSetTraits<_Graph, _Item>
     
    323328    ::Parent Parent;
    324329
     330    /// The key type
    325331    typedef _Item Key;
     332    /// The value type
    326333    typedef int Value;
     334    /// The graph type
    327335    typedef _Graph Graph;
    328336
    329     explicit IterableIntMap(const Graph& graph) : Parent(graph) {}
     337    /// \brief Constructor of the Map.
     338    ///
     339    /// Constructor of the Map. It set all values -1.
     340    explicit IterableIntMap(const Graph& graph)
     341      : Parent(graph, _iterable_maps_bits::IterableIntMapNode<_Item>(-1)) {}
     342
     343    /// \brief Constructor of the Map with a given value.
     344    ///
     345    /// Constructor of the Map with a given value.
     346    explicit IterableIntMap(const Graph& graph, int value)
     347      : Parent(graph, _iterable_maps_bits::IterableIntMapNode<_Item>(value)) {
     348      if (value >= 0) {
     349        for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
     350          lace(it);
     351        }
     352      }
     353    }
    330354
    331355  private:
     
    363387  public:
    364388
     389    /// Indicates that the map if reference map.
    365390    typedef True ReferenceMapTag;
    366391
     392    /// \brief Refernce to the value of the map.
     393    ///
     394    /// This class is near to similar to the int type. It can
     395    /// be converted to int and it has the same operators.
    367396    class Reference {
    368397      friend class IterableIntMap;
     
    448477      IterableIntMap& _map;
    449478    };
    450    
     479
     480    /// The const reference type.   
    451481    typedef const Value& ConstReference;
    452482
     483    /// \brief Gives back the maximal value plus one.
     484    ///
     485    /// Gives back the maximal value plus one.
    453486    int size() const {
    454487      return (int)first.size();
    455488    }
    456489   
     490    /// \brief Set operation of the map.
     491    ///
     492    /// Set operation of the map.
    457493    void set(const Key& key, const Value& value) {
    458494      unlace(key);
     
    461497    }
    462498
     499    /// \brief Const subscript operator of the map.
     500    ///
     501    /// Const subscript operator of the map.
    463502    const Value& operator[](const Key& key) const {
    464503      return Parent::operator[](key).value;
    465504    }
    466505
     506    /// \brief Subscript operator of the map.
     507    ///
     508    /// Subscript operator of the map.
    467509    Reference operator[](const Key& key) {
    468510      return Reference(*this, key);
    469511    }
    470512
     513    /// \brief Iterator for the keys with the same value.
     514    ///
     515    /// Iterator for the keys with the same value. It works
     516    /// like a graph item iterator in the map, it can be converted
     517    /// the item type of the map, incremented with \c ++ operator, and
     518    /// if the iterator leave the last valid item it will be equal to
     519    /// \c INVALID.
    471520    class ItemIt : public _Item {
    472521    public:
    473522      typedef _Item Parent;
    474523
     524      /// \brief Invalid constructor \& conversion.
     525      ///
     526      /// This constructor initializes the item to be invalid.
     527      /// \sa Invalid for more details.
    475528      ItemIt(Invalid) : Parent(INVALID), _map(0) {}
    476529
     530      /// \brief Creates an iterator with a value.
     531      ///
     532      /// Creates an iterator with a value. It iterates on the
     533      /// keys which have the given value.
     534      /// \param map The IterableIntMap
     535      /// \param value The value
    477536      ItemIt(const IterableIntMap& map, int value) : _map(&map) {
    478537        if (value < 0 || value >= (int)_map->first.size()) {     
     
    483542      }
    484543
     544      /// \brief Increment operator.
     545      ///
     546      /// Increment Operator.
    485547      ItemIt& operator++() {
    486548        Parent::operator=(_map->IterableIntMap::Parent::
  • lemon/lp_base.h

    r1787 r1810  
    682682    }
    683683    template<class T>
    684     typename enable_if<typename T::ValueSet::value_type::LpSolverCol,
     684    typename enable_if<typename T::MapIt::Value::LpSolverCol,
    685685                       int>::type
    686686    addColSet(T &t,dummy<2> = 2) {
    687       ///\bug <tt>return addColSet(t.valueSet());</tt> should also work.
    688687      int s=0;
    689       for(typename T::ValueSet::iterator i=t.valueSet().begin();
    690           i!=t.valueSet().end();
    691           ++i)
     688      for(typename T::MapIt i(t); i!=INVALID; ++i)
    692689        {
    693           *i=addCol();
     690          i.set(addCol());
    694691          s++;
    695692        }
     
    788785    }
    789786    template<class T>
    790     typename enable_if<typename T::ValueSet::value_type::LpSolverRow,
     787    typename enable_if<typename T::MapIt::Value::LpSolverRow,
    791788                       int>::type
    792789    addRowSet(T &t,dummy<2> = 2) {
    793       ///\bug <tt>return addRowSet(t.valueSet());</tt> should also work.
    794790      int s=0;
    795       for(typename T::ValueSet::iterator i=t.valueSet().begin();
    796           i!=t.valueSet().end();
    797           ++i)
     791      for(typename T::MapIt i(t); i!=INVALID; ++i)
    798792        {
    799           *i=addRow();
     793          i.set(addRow());
    800794          s++;
    801795        }
Note: See TracChangeset for help on using the changeset viewer.