COIN-OR::LEMON - Graph Library

Changeset 844:9bf990cb066d in lemon-0.x for src


Ignore:
Timestamp:
09/13/04 22:05:13 (20 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1143
Message:

Bug fix in the symmetric maps.
Faster map initialization.
Iterators and Containers STL compatible.

Location:
src
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • src/hugo/Makefile.am

    r843 r844  
    1818        map_iterator.h                                                  \
    1919        map_registry.h                                                  \
     20        map_bits.h                                                      \
    2021        maps.h                                                          \
    2122        mincostflows.h                                                  \
  • src/hugo/array_map.h

    r830 r844  
    66
    77#include <hugo/map_iterator.h>
     8#include <hugo/map_bits.h>
    89
    910///\ingroup graphmaps
     
    7273      allocate_memory();
    7374      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    74         int id = MapBase::getGraph()->id(it);
     75        int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
    7576        allocator.construct(&(values[id]), Value());
    7677      }                                                         
     
    8384      allocate_memory();
    8485      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    85         int id = MapBase::getGraph()->id(it);
     86        int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
    8687        allocator.construct(&(values[id]), v);
    8788      }                                                         
     
    9596      values = allocator.allocate(capacity);
    9697      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    97         int id = MapBase::getGraph()->id(it);
     98        int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
    9899        allocator.construct(&(values[id]), copy.values[id]);
    99100      }
     
    124125      values = allocator.allocate(capacity);
    125126      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    126         int id = MapBase::getGraph()->id(it);
     127        int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
    127128        allocator.construct(&(values[id]), copy.values[id]);
    128129      }
     
    133134     */
    134135    template <typename CMap> ArrayMap& operator=(const CMap& copy) {
    135       if (MapBase::getGraph()) {
     136      if (capacity != 0) {
    136137        MapBase::destroy();
    137       }
     138        allocator.deallocate(values, capacity);
     139      }
    138140      MapBase::operator=(copy);
    139141      if (MapBase::getGraph()) {
     
    161163     */
    162164    ReferenceType operator[](const KeyType& key) {
    163       int id = MapBase::getGraph()->id(key);
     165      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
    164166      return values[id];
    165167    }
     
    170172     */
    171173    ConstReferenceType operator[](const KeyType& key) const {
    172       int id = MapBase::getGraph()->id(key);
     174      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
    173175      return values[id];
    174176    }
     
    178180     */
    179181    void set(const KeyType& key, const ValueType& val) {
    180       int id = MapBase::getGraph()->id(key);
     182      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
    181183      values[id] = val;
    182184    }
     
    185187     */
    186188    void add(const KeyType& key) {
    187       int id = MapBase::getGraph()->id(key);
     189      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
    188190      if (id >= capacity) {
    189191        int new_capacity = (capacity == 0 ? 1 : capacity);
     
    193195        Value* new_values = allocator.allocate(new_capacity);;
    194196        for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    195           int jd = MapBase::getGraph()->id(it);
     197          int jd = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
    196198          if (id != jd) {
    197199            allocator.construct(&(new_values[jd]), values[jd]);
     
    209211     */
    210212    void erase(const KeyType& key) {
    211       int id = MapBase::getGraph()->id(key);
     213      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
    212214      allocator.destroy(&(values[id]));
    213215    }
     
    279281     
    280282    void allocate_memory() {
    281       int max_id = -1;
    282       for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    283         int id = MapBase::getGraph()->id(it);
    284         if (id > max_id) {
    285           max_id = id;
    286         }                       
    287       }
     283      int max_id = KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph());
    288284      if (max_id == -1) {
    289285        capacity = 0;
     
    301297    Value* values;
    302298    Allocator allocator;
     299
     300  public:
     301    // STL  compatibility typedefs.
     302    typedef Iterator iterator;
     303    typedef ConstIterator const_iterator;
     304    typedef typename Iterator::PairValueType value_type;
     305    typedef typename Iterator::KeyType key_type;
     306    typedef typename Iterator::ValueType data_type;
     307    typedef typename Iterator::PairReferenceType reference;
     308    typedef typename Iterator::PairPointerType pointer;
     309    typedef typename ConstIterator::PairReferenceType const_reference;
     310    typedef typename ConstIterator::PairPointerType const_pointer;
     311    typedef int difference_type;               
    303312  };           
    304313
  • src/hugo/graph_wrapper.h

    r838 r844  
    13891389    void erase(const Edge& e) const {
    13901390      Node n=tail(e);
    1391       typename Graph::OutEdgeIt f(*graph, n);
     1391      typename Graph::OutEdgeIt f(*Parent::graph, n);
    13921392      ++f;
    13931393      first_out_edges->set(n, f);
  • src/hugo/list_graph.h

    r827 r844  
    11151115      OutEdgeIt(const EdgeSet& _G,const Node v) :
    11161116        Edge(_G.nodes[v].first_out), G(&_G) { }
    1117       OutEdgeIt &operator++() { n = G->edges[n].next_out; return *this; }
     1117      OutEdgeIt &operator++() {
     1118        Edge::n = G->edges[Edge::n].next_out;
     1119        return *this;
     1120      }
    11181121    };
    11191122   
     
    11271130      InEdgeIt(const EdgeSet& _G,Node v)
    11281131        : Edge(_G.nodes[v].first_in), G(&_G) { }
    1129       InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
     1132      InEdgeIt &operator++() {
     1133        Edge::n = G->edges[Edge::n].next_in;
     1134        return *this;
     1135      }
    11301136    };
    11311137   
  • src/hugo/map_defines.h

    r822 r844  
    9797typedef SymEdgeIt<Graph, Edge, EdgeIt> SymEdgeIt; \
    9898typedef MapRegistry<Graph, Edge, SymEdgeIt> SymEdgeMapRegistry; \
    99 mutable EdgeMapRegistry sym_edge_maps;
     99mutable SymEdgeMapRegistry sym_edge_maps;
    100100
    101101
  • src/hugo/map_iterator.h

    r830 r844  
    22#ifndef MAP_ITERATOR_H
    33#define MAP_ITERATOR_H
     4
     5#include <iterator>
    46
    57#include <hugo/extended_pair.h>
     
    2325
    2426  public:
     27
    2528    /// The key type of the iterator.
    2629    typedef typename Map::KeyType KeyType;
     
    8083    friend class MapConstIterator<Map>;
    8184
    82   public:
     85
     86  public:
     87
     88    /// The iterator base class.
     89    typedef MapIteratorBase<Map> Base;
    8390
    8491    /// The key type of the iterator.
     
    102109   
    103110  public:
     111
     112    /// The value type of the iterator.
     113    typedef extended_pair<KeyType, const KeyType&,
     114      ValueType, const ValueType&> PairValueType;
    104115
    105116    /// The reference type of the iterator.
     
    112123    /// Constructor to initalize the iterators returned
    113124    /// by the begin() and end().
    114     MapIterator(Map& pmap, const KeyIt& pit)
    115       : MapIteratorBase<Map>(pit), map(&pmap) {}
     125    MapIterator(Map& pmap, const KeyIt& pit) : Base(pit), map(&pmap) {}
    116126
    117127    /// Dereference operator for the iterator.
    118128    PairReferenceType operator*() {
    119       return PairReferenceType(it, (*map)[it]);
     129      return PairReferenceType(Base::it, (*map)[Base::it]);
    120130    }
    121131
     
    133143    /// Arrow operator for the iterator.
    134144    PairPointerType operator->() {
    135       return PairPointerType(it, ((*map)[it]));
     145      return PairPointerType(Base::it, ((*map)[Base::it]));
    136146    }
    137147       
    138148    /// The pre increment operator of the iterator.
    139149    MapIterator& operator++() {
    140       increment();
     150      Base::increment();
    141151      return *this;
    142152    }
     
    144154    /// The post increment operator of the iterator.
    145155    MapIterator operator++(int) {
    146       MapIterator tmp(it);
    147       increment();
     156      MapIterator tmp(*this);
     157      Base::increment();
    148158      return tmp;
    149159    }
     
    151161  private:
    152162    Map* map;
     163
     164  public:
     165    // STL  compatibility typedefs.
     166    typedef std::forward_iterator_tag iterator_category;
     167    typedef int difference_type;
     168    typedef PairValueType value_type;
     169    typedef PairReferenceType reference;
     170    typedef PairPointerType pointer;
    153171  };
    154172
     
    160178   
    161179  public:
     180
     181    /// The iterator base class.
     182    typedef MapIteratorBase<Map> Base;
    162183
    163184    /// The key type of the iterator.
     
    188209    ///  by the begin() and end().
    189210    MapConstIterator(const Map& pmap, const KeyIt& pit)
    190       : MapIteratorBase<Map>(pit), map(&pmap) {}
     211      : Base(pit), map(&pmap) {}
    191212
    192213    /// Constructor to create const iterator from a non const.
    193214    MapConstIterator(const MapIterator<Map>& pit) {
    194       it = pit.it;
     215      Base::it = pit.Base::it;
    195216      map = pit.map;
    196217    }
     218
     219    /// The value type of the iterator.
     220    typedef extended_pair<KeyType, const KeyType&,
     221      ValueType, const ValueType&> PairValueType;
    197222
    198223    /// The reference type of map.
     
    202227    /// Dereference operator for the iterator.
    203228    PairReferenceType operator*() {
    204       return PairReferenceType(it, (*map)[it]);
     229      return PairReferenceType(Base::it, (*map)[Base::it]);
    205230    }
    206231
     
    218243    /// Arrow operator for the iterator.
    219244    PairPointerType operator->() {
    220       return PairPointerType(it, ((*map)[it]));
     245      return PairPointerType(Base::it, (*map)[Base::it]);
    221246    }
    222247
    223248    /// The pre increment operator of the iterator.
    224249    MapConstIterator& operator++() {
    225       increment();
     250      Base::increment();
    226251      return *this;
    227252    }
     
    229254    /// The post increment operator of the iterator.
    230255    MapConstIterator operator++(int) {
    231       MapConstIterator<Map> tmp(it);
    232       increment();
     256      MapConstIterator tmp(*this);
     257      Base::increment();
    233258      return tmp;
    234259    }
     
    236261  private:
    237262    const Map* map;
     263
     264  public:
     265    // STL  compatibility typedefs.
     266    typedef std::input_iterator_tag iterator_category;
     267    typedef int difference_type;
     268    typedef PairValueType value_type;
     269    typedef PairReferenceType reference;
     270    typedef PairPointerType pointer;
    238271  };
    239272
     
    246279  public:
    247280
     281    /// The iterator base class.
     282    typedef MapIteratorBase<Map> Base;
     283 
    248284    /// The key type of the iterator.
    249285    typedef typename Map::KeyType KeyType;
     
    257293
    258294    /// KeyIt initialized iterator.
    259     MapKeyIterator(const KeyIt& pit) : MapIteratorBase<Map>(pit) {}
     295    MapKeyIterator(const KeyIt& pit) : Base(pit) {}
    260296
    261297    /// The pre increment operator of the iterator.
    262298    MapKeyIterator& operator++() {
    263       increment();
     299      Base::increment();
    264300      return *this;
    265301    }
     
    268304    MapKeyIterator operator++(int) {
    269305      MapKeyIterator tmp(*this);
    270       increment();
     306      Base::increment();
    271307      return tmp;
    272308    }
     
    274310    /// The dereferencing operator of the iterator.
    275311    KeyType operator*() const {
    276       return static_cast<KeyType>(it);
    277     }
     312      return static_cast<KeyType>(Base::it);
     313    }
     314
     315  public:
     316    // STL  compatibility typedefs.
     317    typedef std::input_iterator_tag iterator_category;
     318    typedef int difference_type;
     319    typedef KeyType value_type;
     320    typedef const KeyType& reference;
     321    typedef const KeyType* pointer;
    278322  };
    279323
    280324  template <typename Map> class MapConstValueIterator;
    281325
     326  /** MapValueIterator creates an stl compatible iterator
     327   *  for the values.
     328   */
    282329  template <typename Map>
    283330  class MapValueIterator : public MapIteratorBase<Map> {
     
    286333
    287334  public:
     335
     336    /// The iterator base class.
     337    typedef MapIteratorBase<Map> Base;
    288338
    289339    /// The key type of the iterator.
     
    318368    /// Map and KeyIt initialized iterator.
    319369    MapValueIterator(Map& pmap, const KeyIt& pit)
    320       : MapIteratorBase<Map>(pit), map(&pmap) {}
     370      : Base(pit), map(&pmap) {}
    321371   
    322372
    323373    /// The pre increment operator of the iterator.
    324374    MapValueIterator& operator++() {
    325       increment();
     375      Base::increment();
    326376      return *this;
    327377    }
     
    330380    MapValueIterator operator++(int) {
    331381      MapValueIterator tmp(*this);
    332       increment();
     382      Base::increment();
    333383      return tmp;
    334384    }
     
    336386    /// The dereferencing operator of the iterator.
    337387    ReferenceType operator*() const {
    338       return (*map)[it];
     388      return (*map)[Base::it];
    339389    }
    340390
     
    344394    }
    345395
    346   };
    347 
     396  public:
     397    // STL  compatibility typedefs.
     398    typedef std::forward_iterator_tag iterator_category;
     399    typedef int difference_type;
     400    typedef ValueType value_type;
     401    typedef ReferenceType reference;
     402    typedef PointerType pointer;
     403  };
     404
     405  /** MapValueIterator creates an stl compatible iterator
     406   *  for the const values.
     407   */
    348408
    349409  template <typename Map>
     
    352412  public:
    353413
    354     /// The key type of the iterator.
    355     typedef typename Map::KeyType KeyType;
    356     /// The iterator to iterate on the keys.
    357     typedef typename Map::KeyIt KeyIt;
    358 
     414    /// The iterator base class.
     415    typedef MapIteratorBase<Map> Base;
     416
     417    /// The key type of the iterator.
     418    typedef typename Map::KeyType KeyType;
     419    /// The iterator to iterate on the keys.
     420    typedef typename Map::KeyIt KeyIt;
    359421
    360422    /// The value type of the iterator.
     
    383445    /// Constructor to create const iterator from a non const.
    384446    MapConstValueIterator(const MapValueIterator<Map>& pit) {
    385       it = pit.it;
     447      Base::it = pit.Base::it;
    386448      map = pit.map;
    387449    }
     
    389451    /// Map and KeyIt initialized iterator.
    390452    MapConstValueIterator(const Map& pmap, const KeyIt& pit)
    391       : MapIteratorBase<Map>(pit), map(&pmap) {}
     453      : Base(pit), map(&pmap) {}
    392454
    393455    /// The pre increment operator of the iterator.
    394456    MapConstValueIterator& operator++() {
    395       increment();
     457      Base::increment();
    396458      return *this;
    397459    }
     
    400462    MapConstValueIterator operator++(int) {
    401463      MapConstValueIterator tmp(*this);
    402       increment();
     464      Base::increment();
    403465      return tmp;
    404466    }
     
    406468    /// The dereferencing operator of the iterator.
    407469    ConstReferenceType operator*() const {
    408       return (*map)[it];
     470      return (*map)[Base::it];
    409471    }
    410472
     
    414476    }
    415477
     478  public:
     479    // STL  compatibility typedefs.
     480    typedef std::input_iterator_tag iterator_category;
     481    typedef int difference_type;
     482    typedef ValueType value_type;
     483    typedef ConstReferenceType reference;
     484    typedef ConstPointerType pointer;
    416485  };
    417486
     
    431500    /// The iterator to iterate on the keys.
    432501    typedef typename Map::KeyIt KeyIt;
     502
     503
     504    /// The value type of the iterator.
     505    typedef typename Map::ValueType ValueType;
     506    /// The reference type of the iterator.
     507    typedef typename Map::ReferenceType ReferenceType;
     508    /// The pointer type of the iterator.
     509    typedef typename Map::PointerType PointerType;
     510
     511    /// The const value type of the iterator.
     512    typedef typename Map::ConstValueType ConstValueType;
     513    /// The const reference type of the iterator.
     514    typedef typename Map::ConstReferenceType ConstReferenceType;
     515    /// The pointer type of the iterator.
     516    typedef typename Map::ConstPointerType ConstPointerType;
    433517
    434518    /// The map initialized const key set.
     
    447531      return ConstIterator(KeyIt(INVALID));
    448532    }
     533 
     534  public:
     535    // STL  compatibility typedefs.
     536    typedef ValueType value_type;
     537    typedef ConstIterator const_iterator;
     538    typedef ConstReferenceType const_reference;
     539    typedef ConstPointerType const_pointer;
     540    typedef int difference_type;
    449541  };
    450542
     
    465557    typedef typename Map::KeyIt KeyIt;
    466558
     559
     560    /// The value type of the iterator.
     561    typedef typename Map::ValueType ValueType;
     562    /// The reference type of the iterator.
     563    typedef typename Map::ReferenceType ReferenceType;
     564    /// The pointer type of the iterator.
     565    typedef typename Map::PointerType PointerType;
     566
     567    /// The const value type of the iterator.
     568    typedef typename Map::ConstValueType ConstValueType;
     569    /// The const reference type of the iterator.
     570    typedef typename Map::ConstReferenceType ConstReferenceType;
     571    /// The pointer type of the iterator.
     572    typedef typename Map::ConstPointerType ConstPointerType;
     573
    467574    /// The map initialized const value set.
    468575    MapConstValueSet(const Map& pmap) : map(&pmap) {}
     
    480587      return ConstIterator(*map, KeyIt(INVALID));
    481588    }
     589
     590  public:
     591    // STL  compatibility typedefs.
     592    typedef ValueType value_type;
     593    typedef ConstIterator const_iterator;
     594    typedef ConstReferenceType const_reference;
     595    typedef ConstPointerType const_pointer;
     596    typedef int difference_type;
    482597  };
    483598
     
    499614    typedef typename Map::KeyIt KeyIt;
    500615
     616
     617    /// The value type of the iterator.
     618    typedef typename Map::ValueType ValueType;
     619    /// The reference type of the iterator.
     620    typedef typename Map::ReferenceType ReferenceType;
     621    /// The pointer type of the iterator.
     622    typedef typename Map::PointerType PointerType;
     623
     624    /// The const value type of the iterator.
     625    typedef typename Map::ConstValueType ConstValueType;
     626    /// The const reference type of the iterator.
     627    typedef typename Map::ConstReferenceType ConstReferenceType;
     628    /// The pointer type of the iterator.
     629    typedef typename Map::ConstPointerType ConstPointerType;
     630
    501631    /// The map initialized value set.
    502632    MapValueSet(Map& pmap) : map(&pmap) {}
     
    528658    }
    529659           
     660  public:
     661    // STL  compatibility typedefs.
     662    typedef ValueType value_type;
     663    typedef Iterator iterator;
     664    typedef ConstIterator const_iterator;
     665    typedef ReferenceType reference;
     666    typedef ConstReferenceType const_reference;
     667    typedef PointerType pointer;
     668    typedef ConstPointerType const_pointer;
     669    typedef int difference_type;
     670
    530671  };
    531672
  • src/hugo/sym_map.h

    r822 r844  
    1818   */
    1919
     20
    2021  template <typename Graph, typename Edge, typename EdgeIt>
    2122  class SymEdgeIt : public EdgeIt {
     
    3132    SymEdgeIt(const Graph& graph)
    3233      : EdgeIt(graph) {
    33       while ( (n & 1) && n != -1) {
     34      while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
    3435        EdgeIt::operator++();
    3536      }
     
    4546    SymEdgeIt(const Graph& graph, const Edge& edge)
    4647      : EdgeIt(graph, edge) {
    47       while ( (n & 1) && n != -1) {
     48      while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
    4849        EdgeIt::operator++();
    4950      }
     
    5455    SymEdgeIt& operator++() {
    5556      EdgeIt::operator++();
    56       while ( (n & 1) && n != -1) {
     57      while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
    5758        EdgeIt::operator++();
    5859      }
     
    122123    }
    123124   
    124     /**
    125      * The subscript operator. The map can be subscripted by the
    126      * actual keys of the graph.
    127      */
    128     typename MapImpl::ReferenceType operator[](const KeyType& key) {
    129       int id = MapImpl::getGraph()->id(key);   
    130       return MapImpl::operator[](id >> 1);
    131     }
    132                
    133     /**
    134      * The const subscript operator. The map can be subscripted by the
    135      * actual keys of the graph.
    136      */
    137     typename MapImpl::ConstReferenceType operator[](const KeyType& key) const {
    138       int id = MapImpl::getGraph()->id(key);
    139       return MapImpl::operator[](id >> 1);
    140     }
    141        
    142     /** Setter function of the map. Equivalent with map[key] = val.
    143      *  This is a compatibility feature with the not dereferable maps.
    144      */
    145     void set(const KeyType& key, const typename MapImpl::ValueType& val) {
    146       int id = MapImpl::getGraph()->id(key);
    147       MapImpl::operator[](id >> 1) = val;
    148     }
    149                
    150125    /** Add a new key to the map. It called by the map registry.
    151126     */
  • src/hugo/vector_map.h

    r830 r844  
    66
    77#include <hugo/map_iterator.h>
     8#include <hugo/map_bits.h>
    89
    910///\ingroup graphmaps
     
    7475    /** Graph and Registry initialized map constructor.
    7576     */
    76     VectorMap(const Graph& g, MapRegistry& r) : MapBase(g, r) {
    77       init();
    78     }
     77    VectorMap(const Graph& g, MapRegistry& r)
     78      : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1) {}
    7979
    8080    /** Constructor to use default value to initialize the map.
    8181     */
    8282    VectorMap(const Graph& g, MapRegistry& r, const Value& v)
    83       : MapBase(g, r) {
    84       for (KeyIt it(*getGraph()); it != INVALID; ++it) {
    85         int id = getGraph()->id(it);
    86         if (id >= (int)container.size()) {
    87           container.resize(id + 1);
    88         }
    89         set(it, v);
    90       }
    91     }
     83      : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1, v) {}
    9284
    9385    /** Constructor to copy a map of an other map type.
    9486     */
    9587    template <typename CMap> VectorMap(const CMap& copy) : MapBase(copy) {
    96       if (getGraph()) {
    97         for (KeyIt it(*getGraph()); it != INVALID; ++it) {
    98           int id = getGraph()->id(it);
    99           if (id >= (int)container.size()) {
    100             container.resize(id + 1);
    101           }
     88      if (MapBase::getGraph()) {
     89        container.resize(KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph())+1);
     90        for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    10291          set(it, copy[it]);
    10392        }
     
    10897     */
    10998    template <typename CMap> VectorMap& operator=(const CMap& copy) {
    110       if (getGraph()) {
    111         destroy();
    112       }
     99      container.clear();
    113100      this->MapBase::operator=(copy);
    114       if (getGraph()) {
    115         for (KeyIt it(*getGraph()); it != INVALID; ++it) {
    116           int id = getGraph()->id(it);
    117           if (id >= (int)container.size()) {
    118             container.resize(id + 1);
    119           }
     101      if (MapBase::getGraph()) {
     102        container.resize(KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph())+1);
     103        for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    120104          set(it, copy[it]);
    121105        }
     
    134118     */
    135119    ReferenceType operator[](const KeyType& key) {
    136       int id = getGraph()->id(key);
     120      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
    137121      return container[id];
    138122    }
     
    143127     */
    144128    ConstReferenceType operator[](const KeyType& key) const {
    145       int id = getGraph()->id(key);
     129      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
    146130      return container[id];
    147131    }
     
    151135     */
    152136    void set(const KeyType& key, const ValueType& val) {
    153       int id = getGraph()->id(key);
     137      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
    154138      container[id] = val;
    155139    }
     
    158142     */
    159143    void add(const KeyType& key) {
    160       int id = getGraph()->id(key);
     144      int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), key);
    161145      if (id >= (int)container.size()) {
    162146        container.resize(id + 1);
     
    232216    Container container;
    233217
    234                
     218  public:
     219    // STL  compatibility typedefs.
     220    typedef Iterator iterator;
     221    typedef ConstIterator const_iterator;
     222    typedef typename Iterator::PairValueType value_type;
     223    typedef typename Iterator::KeyType key_type;
     224    typedef typename Iterator::ValueType data_type;
     225    typedef typename Iterator::PairReferenceType reference;
     226    typedef typename Iterator::PairPointerType pointer;
     227    typedef typename ConstIterator::PairReferenceType const_reference;
     228    typedef typename ConstIterator::PairPointerType const_pointer;
     229    typedef int difference_type;               
    235230  };
    236231 
  • src/test/test_tools.h

    r825 r844  
     1// -*- c++ -*-
    12#ifndef HUGO_TEST_TEST_TOOLS_H
    23#define HUGO_TEST_TEST_TOOLS_H
Note: See TracChangeset for help on using the changeset viewer.