COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/maps.h

    r684 r617  
    19031903
    19041904  /// This class provides simple invertable graph maps.
    1905   /// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap)
    1906   /// and if a key is set to a new value, then stores it in the inverse map.
     1905  /// It wraps an arbitrary \ref concepts::ReadWriteMap "ReadWriteMap"
     1906  /// and if a key is set to a new value then store it
     1907  /// in the inverse map.
     1908  ///
    19071909  /// The values of the map can be accessed
    19081910  /// with stl compatible forward iterator.
    1909   ///
    1910   /// This type is not reference map, so it cannot be modified with
    1911   /// the subscript operator.
    19121911  ///
    19131912  /// \tparam GR The graph type.
     
    19251924      template Map<V>::Type Map;
    19261925
    1927     typedef std::multimap<V, K> Container;
     1926    typedef std::map<V, K> Container;
    19281927    Container _inv_map;
    19291928
     
    19501949    /// iterator on the values of the map. The values can
    19511950    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
    1952     /// They are considered with multiplicity, so each value is
    1953     /// traversed for each item it is assigned to.
    19541951    class ValueIterator
    19551952      : public std::iterator<std::forward_iterator_tag, Value> {
     
    20042001    void set(const Key& key, const Value& val) {
    20052002      Value oldval = Map::operator[](key);
    2006       typename Container::iterator it;
    2007       for (it = _inv_map.equal_range(oldval).first;
    2008            it != _inv_map.equal_range(oldval).second; ++it) {
    2009         if (it->second == key) {
    2010           _inv_map.erase(it);
    2011           break;
    2012         }
     2003      typename Container::iterator it = _inv_map.find(oldval);
     2004      if (it != _inv_map.end() && it->second == key) {
     2005        _inv_map.erase(it);
    20132006      }
    2014       _inv_map.insert(std::make_pair(val, key));
     2007      _inv_map.insert(make_pair(val, key));
    20152008      Map::set(key, val);
    20162009    }
     
    20242017    }
    20252018
    2026     /// \brief Gives back an item by its value.
    2027     ///
    2028     /// This function gives back an item that is assigned to
    2029     /// the given value or \c INVALID if no such item exists.
    2030     /// If there are more items with the same associated value,
    2031     /// only one of them is returned.
    2032     Key operator()(const Value& val) const {
    2033       typename Container::const_iterator it = _inv_map.find(val);
     2019    /// \brief Gives back the item by its value.
     2020    ///
     2021    /// Gives back the item by its value.
     2022    Key operator()(const Value& key) const {
     2023      typename Container::const_iterator it = _inv_map.find(key);
    20342024      return it != _inv_map.end() ? it->second : INVALID;
    20352025    }
     
    20432033    virtual void erase(const Key& key) {
    20442034      Value val = Map::operator[](key);
    2045       typename Container::iterator it;
    2046       for (it = _inv_map.equal_range(val).first;
    2047            it != _inv_map.equal_range(val).second; ++it) {
    2048         if (it->second == key) {
    2049           _inv_map.erase(it);
    2050           break;
    2051         }
     2035      typename Container::iterator it = _inv_map.find(val);
     2036      if (it != _inv_map.end() && it->second == key) {
     2037        _inv_map.erase(it);
    20522038      }
    20532039      Map::erase(key);
     
    20612047      for (int i = 0; i < int(keys.size()); ++i) {
    20622048        Value val = Map::operator[](keys[i]);
    2063         typename Container::iterator it;
    2064         for (it = _inv_map.equal_range(val).first;
    2065              it != _inv_map.equal_range(val).second; ++it) {
    2066           if (it->second == keys[i]) {
    2067             _inv_map.erase(it);
    2068             break;
    2069           }
     2049        typename Container::iterator it = _inv_map.find(val);
     2050        if (it != _inv_map.end() && it->second == keys[i]) {
     2051          _inv_map.erase(it);
    20702052        }
    20712053      }
     
    21032085      /// \brief Subscript operator.
    21042086      ///
    2105       /// Subscript operator. It gives back an item
    2106       /// that is assigned to the given value or \c INVALID
    2107       /// if no such item exists.
     2087      /// Subscript operator. It gives back the item
     2088      /// that was last assigned to the given value.
    21082089      Value operator[](const Key& key) const {
    21092090        return _inverted(key);
Note: See TracChangeset for help on using the changeset viewer.