COIN-OR::LEMON - Graph Library

Changeset 1115:444f69240539 in lemon-0.x for src/work/deba/map_utils.h


Ignore:
Timestamp:
02/01/05 16:56:37 (20 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1514
Message:

Some changes in the IO and map utilities.

File:
1 edited

Legend:

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

    r1037 r1115  
    1515 */
    1616
    17 ///\ingroup gutils
     17///\ingroup mutils
    1818///\file
    1919///\brief Map utilities.
     
    5050    typedef typename _Map::ConstReference ConstReference;
    5151
    52     /// Constructor.
    53 
     52    /// \brief Constructor.
     53    ///
    5454    /// Construct a new InversableMap for the graph.
    5555    ///
    5656    InversableMap(const Graph& graph) : Map(graph) {}
    5757   
    58     /// The setter function of the map.
    59 
    60     /// It sets the map and the inverse map
     58    /// \brief The setter function of the map.
     59    ///
     60    /// It sets the map and the inverse map to given key-value pair.
    6161    void set(const Key& key, const Value& val) {
    6262      Value oldval = Map::operator[](key);
     
    9696
    9797
    98   // unique, continous, mutable
     98 
     99  /// \brief Provides a mutable, continous and unique descriptor for each
     100  /// item in the graph.
     101  ///
     102  /// The DescriptorMap class provides a mutable, continous and immutable
     103  /// mapping for each item in the graph.
     104  ///
     105  /// \param _Graph The graph class the \c DescriptorMap belongs to.
     106  /// \param _Item The Item is the Key of the Map. It may be Node, Edge or
     107  /// UndirEdge.
     108  /// \param _Map A ReadWriteMap mapping from the item type to integer.
    99109
    100110  template <
    101111    typename _Graph,   
    102112    typename _Item,
    103     typename _ItemIt,
    104113    typename _Map
    105114  >
    106115  class DescriptorMap : protected _Map {
     116
     117    typedef _Item Item;
     118    typedef _Map Map;
     119
    107120  public:
     121    /// The graph class of DescriptorMap.
    108122    typedef _Graph Graph;
    109     typedef _Item Item;
    110     typedef _ItemIt ItemIt;
    111     typedef _Map Map;
    112 
    113 
     123
     124    /// The key type of DescriptorMap (Node, Edge, UndirEdge).
    114125    typedef typename _Map::Key Key;
     126    /// The value type of DescriptorMap.
    115127    typedef typename _Map::Value Value;
    116128
    117     typedef vector<Item> InverseMap;
    118 
     129    typedef std::vector<Item> InverseMap;
     130
     131    /// \brief Constructor.
     132    ///
     133    /// Constructor for creating descriptor map.
    119134    DescriptorMap(const Graph& _graph) : Map(_graph) {
    120135      build();
     
    135150    virtual void build() {
    136151      Map::build();
    137       for (ItemIt it(*Map::getGraph()); it != INVALID; ++it) {
     152      Item it;
     153      for (getGraph()->first(it); it != INVALID; getGraph()->next(it)) {
    138154        Map::set(it, inv_map.size());
    139155        inv_map.push_back(it); 
     
    146162    }
    147163
     164    /// \brief Gives back the \e descriptor of the item.
     165    ///
     166    /// Gives back the mutable and unique \e descriptor of the map.
    148167    int operator[](const Item& item) const {
    149168      return Map::operator[](item);
    150169    }
    151 
    152    
     170   
     171    /// \brief Gives back the inverse of the map.
     172    ///
     173    /// Gives back the inverse of the map.
    153174    const InverseMap inverse() const {
    154175      return inv_map;
     
    158179    vector<Item> inv_map;
    159180  };
    160 
    161   // unique, immutable => IDMap
    162181 
    163  
     182  /// Provides an immutable and unique id for each item in the graph.
     183
     184  /// The IdMap class provides an unique and immutable mapping for each item
     185  /// in the graph.
     186  ///
     187  template <typename _Graph, typename _Item>
     188  class IdMap {
     189  public:
     190    typedef _Graph Graph;
     191    typedef int Value;
     192    typedef _Item Item;
     193
     194    /// \brief The class represents the inverse of the map.
     195    ///
     196    /// The class represents the inverse of the map.
     197    /// \see inverse()
     198    class InverseMap {
     199    protected:
     200      InverseMap(const Graph& _graph) : graph(_graph) {}
     201    public:
     202      /// \brief Gives back the given item by its id.
     203      ///
     204      /// Gives back the given item by its id.
     205      ///
     206      Item operator[](int id) const { return graph->fromId(id, Item());}
     207    private:
     208      Graph* graph;
     209    };
     210
     211    /// \brief Constructor.
     212    ///
     213    /// Constructor for creating id map.
     214    IdMap(const Graph& _graph) : graph(&_graph) {}
     215
     216    /// \brief Gives back the \e id of the item.
     217    ///
     218    /// Gives back the immutable and unique \e id of the map.
     219    int operator[](const Item& item) const { return graph->id(item);}
     220
     221    /// \brief Gives back the inverse of the map.
     222    ///
     223    /// Gives back the inverse of the map.
     224    InverseMap inverse() const { return InverseMap(*graph);}
     225
     226  private:
     227    const Graph* graph;
     228
     229  };
     230
     231
    164232
    165233}
Note: See TracChangeset for help on using the changeset viewer.