COIN-OR::LEMON - Graph Library

Changeset 891:74589d20dbc3 in lemon-0.x for src/hugo/array_map.h


Ignore:
Timestamp:
09/21/04 00:57:48 (20 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1199
Message:

template<typename CMap> Map(const CMap&) like constructors and
assigns are removed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/hugo/array_map.h

    r844 r891  
    6666    /** Default constructor for the map.
    6767     */
    68     ArrayMap() : values(0), capacity(0) {}
     68    ArrayMap() : capacity(0), values(0) {}
    6969                       
    7070    /** Graph and Registry initialized map constructor.
     
    9191    /** Constructor to copy a map of the same map type.
    9292     */
    93     ArrayMap(const ArrayMap& copy) : MapBase(*copy.graph, *copy.registry) {
     93    ArrayMap(const ArrayMap& copy) : MapBase(copy) {
    9494      capacity = copy.capacity;
    9595      if (capacity == 0) return;
     
    103103    /** Constructor to copy a map of an other map type.
    104104     */
    105     template <typename CMap> ArrayMap(const CMap& copy)
    106       : MapBase(copy), capacity(0), values(0) {
    107       if (MapBase::getGraph()) {
    108         allocate_memory();
    109         for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    110           set(it, copy[it]);
    111         }
     105    template <typename TT>
     106    ArrayMap(const ArrayMap<MapRegistry, TT>& copy)
     107      : MapBase(copy) {
     108      capacity = copy.capacity;
     109      if (capacity == 0) return;
     110      values = allocator.allocate(capacity);
     111      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
     112        int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
     113        allocator.construct(&(values[id]), copy.values[id]);
    112114      }
    113115    }
     
    117119    ArrayMap& operator=(const ArrayMap& copy) {
    118120      if (&copy == this) return *this;
     121
    119122      if (capacity != 0) {
    120123        MapBase::destroy();
    121124        allocator.deallocate(values, capacity);
    122125      }
     126
     127      MapBase::operator=(copy);
     128
    123129      capacity = copy.capacity;
    124130      if (capacity == 0) return *this;
    125131      values = allocator.allocate(capacity);
     132
    126133      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    127134        int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
    128135        allocator.construct(&(values[id]), copy.values[id]);
    129136      }
     137
    130138      return *this;
    131139    }
    132140
    133     /** Assign operator to copy a map an other map type.
    134      */
    135     template <typename CMap> ArrayMap& operator=(const CMap& copy) {
     141    /** Assign operator to copy a map of an other map type.
     142     */
     143    template <typename TT>
     144    ArrayMap& operator=(const ArrayMap<MapRegistry, TT>& copy) {
    136145      if (capacity != 0) {
    137146        MapBase::destroy();
    138147        allocator.deallocate(values, capacity);
    139148      }
     149
    140150      MapBase::operator=(copy);
    141       if (MapBase::getGraph()) {
    142         allocate_memory();
    143         for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
    144           set(it, copy[it]);
    145         }
    146       }
     151
     152      capacity = copy.capacity;
     153      if (capacity == 0) return *this;
     154      values = allocator.allocate(capacity);
     155
     156      for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) {
     157        int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it);
     158        allocator.construct(&(values[id]), copy.values[id]);
     159      }
     160
    147161      return *this;
    148162    }
Note: See TracChangeset for help on using the changeset viewer.