COIN-OR::LEMON - Graph Library

Changeset 1133:9fd485470fee in lemon-0.x for src/work/deba/map_utils.h


Ignore:
Timestamp:
02/07/05 11:48:14 (19 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1532
Message:

Documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/work/deba/map_utils.h

    r1115 r1133  
    2424namespace lemon {
    2525
    26   /// \addtogroup gutils
     26  /// \addtogroup mutils
    2727  /// @{
    28 
    2928
    3029  /// \brief General inversable map type.
     
    3433  /// and if a key is setted to a new value then store it
    3534  /// in the inverse map.
     35  /// \param _Graph The graph type.
     36  /// \param _Map The map to extend with inversable functionality.
    3637  template <
    3738    typename _Graph,
     
    4445
    4546    typedef _Map Map;
     47    /// The key type of InversableMap (Node, Edge, UndirEdge).
    4648    typedef typename _Map::Key Key;
     49    /// The value type of the InversableMap.
    4750    typedef typename _Map::Value Value;
    4851    typedef std::map<Value, Key> InverseMap;
     
    6164    void set(const Key& key, const Value& val) {
    6265      Value oldval = Map::operator[](key);
    63       typename InverseMap::iterator it = inv_map.find(oldval);
    64       if (it != inv_map.end() && it->second == key) {
    65         inv_map.erase(it);
     66      typename InverseMap::iterator it = invMap.find(oldval);
     67      if (it != invMap.end() && it->second == key) {
     68        invMap.erase(it);
    6669      }     
    67       inv_map.insert(make_pair(val, key));
     70      invMap.insert(make_pair(val, key));
    6871      Map::set(key, val);
    6972    }
    7073
    71     ConstReference operator[](const Key&) const {
     74    /// \brief The getter function of the map.
     75    ///
     76    /// It gives back the value associated with the key.
     77    ConstReference operator[](const Key& key) const {
    7278      return Map::operator[](key);
    7379    }
    7480
    75     virtual void add(const Key&) {
     81    /// \brief Add a new key to the map.
     82    ///
     83    /// Add a new key to the map. It is called by the
     84    /// \c AlterationNotifier.
     85    virtual void add(const Key& key) {
    7686      Map::add(key);
    7787    }
    7888
    79     virtual void erase(const Key&) {
     89    /// \brief Erase the key from the map.
     90    ///
     91    /// Erase the key to the map. It is called by the
     92    /// \c AlterationNotifier.
     93    virtual void erase(const Key& key) {
    8094      Value val = Map::operator[](key);
    81       typename InverseMap::iterator it = inv_map.find(val);
    82       if (it != inv_map.end() && it->second == key) {
     95      typename InverseMap::iterator it = invMap.find(val);
     96      if (it != invMap.end() && it->second == key) {
    8397        invMap.erase(it);
    8498      }
     
    86100    }
    87101
     102    /// \brief Clear the keys from the map and inverse map.
     103    ///
     104    /// Clear the keys from the map and inverse map. It is called by the
     105    /// \c AlterationNotifier.
     106    virtual void clear() {
     107      invMap.clear();
     108      Map::clear();
     109    }
     110
     111    /// \brief It gives back the just readeable inverse map.
     112    ///
     113    /// It gives back the just readeable inverse map.
    88114    const InverseMap& inverse() const {
    89       return inv_map;
     115      return invMap;
    90116    }
    91117
    92118
    93119  private:
    94     InverseMap inv_map;   
     120    InverseMap invMap;   
    95121  };
    96122
     
    136162    }
    137163
     164    /// \brief Add a new key to the map.
     165    ///
     166    /// Add a new key to the map. It is called by the
     167    /// \c AlterationNotifier.
    138168    virtual void add(const Item& item) {
    139169      Map::add(item);
    140       Map::set(item, inv_map.size());
    141       inv_map.push_back(item);
    142     }
    143 
     170      Map::set(item, invMap.size());
     171      invMap.push_back(item);
     172    }
     173
     174    /// \brief Erase the key from the map.
     175    ///
     176    /// Erase the key to the map. It is called by the
     177    /// \c AlterationNotifier.
    144178    virtual void erase(const Item& item) {
    145       Map::set(inv_map.back(), Map::operator[](item));
    146       inv_map[Map::operator[](item)] = inv_map.back();
     179      Map::set(invMap.back(), Map::operator[](item));
     180      invMap[Map::operator[](item)] = invMap.back();
    147181      Map::erase(item);
    148182    }
    149183
     184    /// \brief Build the unique map.
     185    ///
     186    /// Build the unique map. It is called by the
     187    /// \c AlterationNotifier.
    150188    virtual void build() {
    151189      Map::build();
    152190      Item it;
    153191      for (getGraph()->first(it); it != INVALID; getGraph()->next(it)) {
    154         Map::set(it, inv_map.size());
    155         inv_map.push_back(it); 
     192        Map::set(it, invMap.size());
     193        invMap.push_back(it);   
    156194      }     
    157195    }
    158196   
     197    /// \brief Clear the keys from the map.
     198    ///
     199    /// Clear the keys from the map. It is called by the
     200    /// \c AlterationNotifier.
    159201    virtual void clear() {
    160       inv_map.clear();
     202      invMap.clear();
    161203      Map::clear();
    162204    }
     
    173215    /// Gives back the inverse of the map.
    174216    const InverseMap inverse() const {
    175       return inv_map;
     217      return invMap;
    176218    }
    177219
    178220  private:
    179     vector<Item> inv_map;
     221    vector<Item> invMap;
    180222  };
    181223 
Note: See TracChangeset for help on using the changeset viewer.