COIN-OR::LEMON - Graph Library

Changeset 844:9bf990cb066d in lemon-0.x for src/hugo/vector_map.h


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.