COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/maps.h

    r768 r741  
    18261826  /// the items stored in the graph, which is returned by the \c id()
    18271827  /// function of the graph. This map can be inverted with its member
    1828   /// class \c InverseMap or with the \c operator()() member.
     1828  /// class \c InverseMap or with the \c operator() member.
    18291829  ///
    18301830  /// \tparam GR The graph type.
     
    19021902
    19031903  /// This class provides simple invertable graph maps.
    1904   /// 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.
     1904  /// It wraps an arbitrary \ref concepts::ReadWriteMap "ReadWriteMap"
     1905  /// and if a key is set to a new value then store it
     1906  /// in the inverse map.
    19061907  /// The values of the map can be accessed
    19071908  /// with stl compatible forward iterator.
    19081909  ///
    19091910  /// This type is not reference map, so it cannot be modified with
    1910   /// the subscript operator.
     1911  /// the subscription operator.
    19111912  ///
    19121913  /// \tparam GR The graph type.
     
    19241925      template Map<V>::Type Map;
    19251926
    1926     typedef std::multimap<V, K> Container;
     1927    typedef std::map<V, K> Container;
    19271928    Container _inv_map;
    19281929
     
    19491950    /// iterator on the values of the map. The values can
    19501951    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
    1951     /// They are considered with multiplicity, so each value is
    1952     /// traversed for each item it is assigned to.
    19531952    class ValueIterator
    19541953      : public std::iterator<std::forward_iterator_tag, Value> {
     
    20032002    void set(const Key& key, const Value& val) {
    20042003      Value oldval = Map::operator[](key);
    2005       typename Container::iterator it;
    2006       for (it = _inv_map.equal_range(oldval).first;
    2007            it != _inv_map.equal_range(oldval).second; ++it) {
    2008         if (it->second == key) {
    2009           _inv_map.erase(it);
    2010           break;
    2011         }
     2004      typename Container::iterator it = _inv_map.find(oldval);
     2005      if (it != _inv_map.end() && it->second == key) {
     2006        _inv_map.erase(it);
    20122007      }
    20132008      _inv_map.insert(std::make_pair(val, key));
     
    20232018    }
    20242019
    2025     /// \brief Gives back an item by its value.
    2026     ///
    2027     /// This function gives back an item that is assigned to
    2028     /// the given value or \c INVALID if no such item exists.
    2029     /// If there are more items with the same associated value,
    2030     /// only one of them is returned.
    2031     Key operator()(const Value& val) const {
    2032       typename Container::const_iterator it = _inv_map.find(val);
     2020    /// \brief Gives back the item by its value.
     2021    ///
     2022    /// Gives back the item by its value.
     2023    Key operator()(const Value& key) const {
     2024      typename Container::const_iterator it = _inv_map.find(key);
    20332025      return it != _inv_map.end() ? it->second : INVALID;
    2034     }
    2035    
    2036     /// \brief Returns the number of items with the given value.
    2037     ///
    2038     /// This function returns the number of items with the given value
    2039     /// associated with it.
    2040     int count(const Value &val) const {
    2041       return _inv_map.count(val);
    20422026    }
    20432027
     
    20502034    virtual void erase(const Key& key) {
    20512035      Value val = Map::operator[](key);
    2052       typename Container::iterator it;
    2053       for (it = _inv_map.equal_range(val).first;
    2054            it != _inv_map.equal_range(val).second; ++it) {
    2055         if (it->second == key) {
    2056           _inv_map.erase(it);
    2057           break;
    2058         }
     2036      typename Container::iterator it = _inv_map.find(val);
     2037      if (it != _inv_map.end() && it->second == key) {
     2038        _inv_map.erase(it);
    20592039      }
    20602040      Map::erase(key);
     
    20682048      for (int i = 0; i < int(keys.size()); ++i) {
    20692049        Value val = Map::operator[](keys[i]);
    2070         typename Container::iterator it;
    2071         for (it = _inv_map.equal_range(val).first;
    2072              it != _inv_map.equal_range(val).second; ++it) {
    2073           if (it->second == keys[i]) {
    2074             _inv_map.erase(it);
    2075             break;
    2076           }
     2050        typename Container::iterator it = _inv_map.find(val);
     2051        if (it != _inv_map.end() && it->second == keys[i]) {
     2052          _inv_map.erase(it);
    20772053        }
    20782054      }
     
    21102086      /// \brief Subscript operator.
    21112087      ///
    2112       /// Subscript operator. It gives back an item
    2113       /// that is assigned to the given value or \c INVALID
    2114       /// if no such item exists.
     2088      /// Subscript operator. It gives back the item
     2089      /// that was last assigned to the given value.
    21152090      Value operator[](const Key& key) const {
    21162091        return _inverted(key);
     
    21302105  };
    21312106
    2132   /// \brief Provides continuous and unique id for the
     2107  /// \brief Provides continuous and unique ID for the
    21332108  /// items of a graph.
    21342109  ///
    21352110  /// RangeIdMap provides a unique and continuous
    2136   /// id for each item of a given type (\c Node, \c Arc or
     2111  /// ID for each item of a given type (\c Node, \c Arc or
    21372112  /// \c Edge) in a graph. This id is
    21382113  ///  - \b unique: different items get different ids,
     
    21452120  /// the \c id() function of the graph or \ref IdMap.
    21462121  /// This map can be inverted with its member class \c InverseMap,
    2147   /// or with the \c operator()() member.
     2122  /// or with the \c operator() member.
    21482123  ///
    21492124  /// \tparam GR The graph type.
Note: See TracChangeset for help on using the changeset viewer.