COIN-OR::LEMON - Graph Library

Ticket #160: 66969f54d61d.patch

File 66969f54d61d.patch, 8.7 KB (added by Alpar Juttner, 16 years ago)
  • lemon/maps.h

    # HG changeset patch
    # User Alpar Juttner <alpar@cs.elte.hu>
    # Date 1238826658 -3600
    # Node ID 66969f54d61de7c2024d58358135912901540862
    # Parent  eda12d8ac95313c837f493e8fd2ca49adc49de26
    DescriptorMap->RangeIdMap, InvertableMap->CrossRefMap (#160)
    
    diff --git a/lemon/maps.h b/lemon/maps.h
    a b  
    18321832  /// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or
    18331833  /// \c GR::Edge).
    18341834  ///
    1835   /// \see DescriptorMap
     1835  /// \see RangeIdMap
    18361836  template <typename GR, typename K>
    18371837  class IdMap : public MapBase<K, int> {
    18381838  public:
     
    18981898  };
    18991899
    19001900
    1901   /// \brief General invertable graph map type.
     1901  /// \brief General cross reference graph map type.
    19021902
    19031903  /// This class provides simple invertable graph maps.
    19041904  /// It wraps an arbitrary \ref concepts::ReadWriteMap "ReadWriteMap"
     
    19151915  ///
    19161916  /// \see IterableValueMap
    19171917  template <typename GR, typename K, typename V>
    1918   class InvertableMap
     1918  class CrossRefMap
    19191919    : protected ItemSetTraits<GR, K>::template Map<V>::Type {
    19201920  private:
    19211921
     
    19271927
    19281928  public:
    19291929
    1930     /// The graph type of InvertableMap.
     1930    /// The graph type of CrossRefMap.
    19311931    typedef GR Graph;
    1932     /// The key type of InvertableMap (\c Node, \c Arc or \c Edge).
     1932    /// The key type of CrossRefMap (\c Node, \c Arc or \c Edge).
    19331933    typedef K Item;
    1934     /// The key type of InvertableMap (\c Node, \c Arc or \c Edge).
     1934    /// The key type of CrossRefMap (\c Node, \c Arc or \c Edge).
    19351935    typedef K Key;
    1936     /// The value type of InvertableMap.
     1936    /// The value type of CrossRefMap.
    19371937    typedef V Value;
    19381938
    19391939    /// \brief Constructor.
    19401940    ///
    1941     /// Construct a new InvertableMap for the given graph.
    1942     explicit InvertableMap(const Graph& graph) : Map(graph) {}
     1941    /// Construct a new CrossRefMap for the given graph.
     1942    explicit CrossRefMap(const Graph& graph) : Map(graph) {}
    19431943
    19441944    /// \brief Forward iterator for values.
    19451945    ///
     
    19481948    /// be accessed in the <tt>[beginValue, endValue)</tt> range.
    19491949    class ValueIterator
    19501950      : public std::iterator<std::forward_iterator_tag, Value> {
    1951       friend class InvertableMap;
     1951      friend class CrossRefMap;
    19521952    private:
    19531953      ValueIterator(typename Container::const_iterator _it)
    19541954        : it(_it) {}
     
    20722072      /// \brief Constructor
    20732073      ///
    20742074      /// Constructor of the InverseMap.
    2075       explicit InverseMap(const InvertableMap& inverted)
     2075      explicit InverseMap(const CrossRefMap& inverted)
    20762076        : _inverted(inverted) {}
    20772077
    20782078      /// The value type of the InverseMap.
    2079       typedef typename InvertableMap::Key Value;
     2079      typedef typename CrossRefMap::Key Value;
    20802080      /// The key type of the InverseMap.
    2081       typedef typename InvertableMap::Value Key;
     2081      typedef typename CrossRefMap::Value Key;
    20822082
    20832083      /// \brief Subscript operator.
    20842084      ///
     
    20892089      }
    20902090
    20912091    private:
    2092       const InvertableMap& _inverted;
     2092      const CrossRefMap& _inverted;
    20932093    };
    20942094
    20952095    /// \brief It gives back the read-only inverse map.
     
    21012101
    21022102  };
    21032103
    2104   /// \brief Provides a mutable, continuous and unique descriptor for each
    2105   /// item in a graph.
     2104  /// \brief Provides continuous and unique ID for the
     2105  /// items of a graph.
    21062106  ///
    2107   /// DescriptorMap provides a unique and continuous (but mutable)
    2108   /// descriptor (id) for each item of the same type (\c Node, \c Arc or
     2107  /// RangeIdMap provides a unique and continuous
     2108  /// ID for each item of a given type (\c Node, \c Arc or
    21092109  /// \c Edge) in a graph. This id is
    21102110  ///  - \b unique: different items get different ids,
    21112111  ///  - \b continuous: the range of the ids is the set of integers
    21122112  ///    between 0 and \c n-1, where \c n is the number of the items of
    2113   ///    this type (\c Node, \c Arc or \c Edge). So the id of an item can
    2114   ///    change if you delete an other item of the same type, i.e. this
    2115   ///    id is mutable.
     2113  ///    this type (\c Node, \c Arc or \c Edge).
     2114  ///  - So, the ids will can change when you deleting an item of the same type.
    21162115  ///
    21172116  /// Thus this id is not (necessarily) the same as what can get using
    21182117  /// the \c id() function of the graph or \ref IdMap.
     
    21252124  ///
    21262125  /// \see IdMap
    21272126  template <typename GR, typename K>
    2128   class DescriptorMap
     2127  class RangeIdMap
    21292128    : protected ItemSetTraits<GR, K>::template Map<int>::Type {
    21302129
    21312130    typedef typename ItemSetTraits<GR, K>::template Map<int>::Type Map;
    21322131
    21332132  public:
    2134     /// The graph type of DescriptorMap.
     2133    /// The graph type of RangeIdMap.
    21352134    typedef GR Graph;
    2136     /// The key type of DescriptorMap (\c Node, \c Arc or \c Edge).
     2135    /// The key type of RangeIdMap (\c Node, \c Arc or \c Edge).
    21372136    typedef K Item;
    2138     /// The key type of DescriptorMap (\c Node, \c Arc or \c Edge).
     2137    /// The key type of RangeIdMap (\c Node, \c Arc or \c Edge).
    21392138    typedef K Key;
    2140     /// The value type of DescriptorMap.
     2139    /// The value type of RangeIdMap.
    21412140    typedef int Value;
    21422141
    21432142    /// \brief Constructor.
    21442143    ///
    2145     /// Constructor for descriptor map.
    2146     explicit DescriptorMap(const Graph& gr) : Map(gr) {
     2144    /// Constructor.
     2145    explicit RangeIdMap(const Graph& gr) : Map(gr) {
    21472146      Item it;
    21482147      const typename Map::Notifier* nf = Map::notifier();
    21492148      for (nf->first(it); it != INVALID; nf->next(it)) {
     
    22442243      _inv_map[pi] = q;
    22452244    }
    22462245
    2247     /// \brief Gives back the \e descriptor of the item.
     2246    /// \brief Gives back the \e RangeId of the item
    22482247    ///
    2249     /// Gives back the mutable and unique \e descriptor of the map.
     2248    /// Gives back the \e RangeId of the item.
    22502249    int operator[](const Item& item) const {
    22512250      return Map::operator[](item);
    22522251    }
    22532252
    2254     /// \brief Gives back the item by its descriptor.
    2255     ///
    2256     /// Gives back th item by its descriptor.
     2253    /// \brief Gives back the item belonging to a RangeId
     2254    /// 
     2255    /// Gives back the item belonging to a RangeId.
    22572256    Item operator()(int id) const {
    22582257      return _inv_map[id];
    22592258    }
     
    22652264
    22662265  public:
    22672266
    2268     /// \brief The inverse map type of DescriptorMap.
     2267    /// \brief The inverse map type of RangeIdMap.
    22692268    ///
    2270     /// The inverse map type of DescriptorMap.
     2269    /// The inverse map type of RangeIdMap.
    22712270    class InverseMap {
    22722271    public:
    22732272      /// \brief Constructor
    22742273      ///
    22752274      /// Constructor of the InverseMap.
    2276       explicit InverseMap(const DescriptorMap& inverted)
     2275      explicit InverseMap(const RangeIdMap& inverted)
    22772276        : _inverted(inverted) {}
    22782277
    22792278
    22802279      /// The value type of the InverseMap.
    2281       typedef typename DescriptorMap::Key Value;
     2280      typedef typename RangeIdMap::Key Value;
    22822281      /// The key type of the InverseMap.
    2283       typedef typename DescriptorMap::Value Key;
     2282      typedef typename RangeIdMap::Value Key;
    22842283
    22852284      /// \brief Subscript operator.
    22862285      ///
     
    22982297      }
    22992298
    23002299    private:
    2301       const DescriptorMap& _inverted;
     2300      const RangeIdMap& _inverted;
    23022301    };
    23032302
    23042303    /// \brief Gives back the inverse of the map.
  • test/graph_utils_test.cc

    diff --git a/test/graph_utils_test.cc b/test/graph_utils_test.cc
    a b  
    3838    for (int i = 0; i < 10; ++i) {
    3939      digraph.addNode();
    4040    }
    41     DescriptorMap<Digraph, Node> nodes(digraph);
    42     typename DescriptorMap<Digraph, Node>::InverseMap invNodes(nodes);
     41    RangeIdMap<Digraph, Node> nodes(digraph);
     42    typename RangeIdMap<Digraph, Node>::InverseMap invNodes(nodes);
    4343    for (int i = 0; i < 100; ++i) {
    4444      int src = rnd[invNodes.size()];
    4545      int trg = rnd[invNodes.size()];
    4646      digraph.addArc(invNodes[src], invNodes[trg]);
    4747    }
    4848    typename Digraph::template ArcMap<bool> found(digraph, false);
    49     DescriptorMap<Digraph, Arc> arcs(digraph);
     49    RangeIdMap<Digraph, Arc> arcs(digraph);
    5050    for (NodeIt src(digraph); src != INVALID; ++src) {
    5151      for (NodeIt trg(digraph); trg != INVALID; ++trg) {
    5252        for (ConArcIt<Digraph> con(digraph, src, trg); con != INVALID; ++con) {
     
    113113  for (int i = 0; i < 10; ++i) {
    114114    graph.addNode();
    115115  }
    116   DescriptorMap<Graph, Node> nodes(graph);
    117   typename DescriptorMap<Graph, Node>::InverseMap invNodes(nodes);
     116  RangeIdMap<Graph, Node> nodes(graph);
     117  typename RangeIdMap<Graph, Node>::InverseMap invNodes(nodes);
    118118  for (int i = 0; i < 100; ++i) {
    119119    int src = rnd[invNodes.size()];
    120120    int trg = rnd[invNodes.size()];
    121121    graph.addEdge(invNodes[src], invNodes[trg]);
    122122  }
    123123  typename Graph::template EdgeMap<int> found(graph, 0);
    124   DescriptorMap<Graph, Edge> edges(graph);
     124  RangeIdMap<Graph, Edge> edges(graph);
    125125  for (NodeIt src(graph); src != INVALID; ++src) {
    126126    for (NodeIt trg(graph); trg != INVALID; ++trg) {
    127127      for (ConEdgeIt<Graph> con(graph, src, trg); con != INVALID; ++con) {