COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
07/15/04 14:15:58 (20 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@954
Message:
 
File:
1 edited

Legend:

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

    r702 r703  
     1// -*- c++ -*-
    12#ifndef VECTOR_MAP_H
    23#define VECTOR_MAP_H
    34
    45#include <vector>
    5 #include <iostream>
    66
    77#include "extended_pair.h"
     
    5656       */
    5757      Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) {
    58         init();
    5958        for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
    60           set(it, v);
     59          int id = getGraph->id(it);
     60          if (id >= container.size) {
     61            container.resize(id + 1);
     62          }
     63          set(it, v);
    6164        }
    6265      }
     
    6669      template <typename CMap> Map(const CMap& copy) : MapBase(copy) {
    6770        if (getGraph()) {
    68           init();
    6971          for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
     72            int id = getGraph->id(it);
     73            if (id >= container.size) {
     74              container.resize(id + 1);
     75            }
    7076            set(it, copy[it]);
    7177          }
     
    8187        this->MapBase::operator=(copy);
    8288        if (getGraph()) {
    83           init();
    8489          for (KeyIt it(*getGraph()); getGraph()->valid(it); getGraph()->next(it)) {
     90            int id = getGraph->id(it);
     91            if (id >= container.size) {
     92              container.resize(id + 1);
     93            }
    8594            set(it, copy[it]);
    8695          }
     
    91100       */
    92101      virtual ~Map() {
    93         destroy();
    94102      }
    95103               
     
    152160        iterator() {}
    153161
     162        typedef extended_pair<const Key&, const Key&,
     163                              Value&, Value&> Reference;
     164
    154165        /** Dereference operator for map.
    155166         */     
    156         std::pair<const Key, Value> operator*() {
    157           return std::pair<const Key, Value>(it, (*map)[it]);
    158         }
    159 
     167        Reference operator*() {
     168          return Reference(it, (*map)[it]);
     169        }
    160170
    161171        class Pointer {
    162172          friend class iterator;
    163173        private:
    164           typedef extended_pair<const Key&, const Key&, Value&, Value&> Pair;
    165           Pair data;
     174          Reference data;
    166175          Pointer(const Key& key, Value& val) : data(key, val) {}
    167176        public:
    168           Pair* operator->() {return &data;}
     177          Reference* operator->() {return &data;}
    169178        };
    170179
     
    228237         *  by the begin() and end().
    229238         */
    230         const_iterator (Map& pmap, const KeyIt& pit) : map(&pmap), it(pit) {}
     239        const_iterator (const Map& pmap, const KeyIt& pit)
     240          : map(&pmap), it(pit) {}
    231241
    232242      public:
     
    238248        /** Constructor to convert iterator to const_iterator.
    239249         */
    240         const_iterator(iterator p_it) {
    241           it = p_it.it;
    242         }
     250        const_iterator(iterator p_it) : map(p_it.map), it(p_it.it) {}
    243251     
     252        typedef extended_pair<const Key&, const Key&,
     253          const Value&, const Value&> Reference;
     254
    244255        /** Dereference operator for map.
    245256         */     
    246         std::pair<const Key, const Value> operator*() const {
    247           return std::pair<const Key, const Value>(it, (*map)[it]);
    248         }
     257        Reference operator*() {
     258          return Reference(it, (*map)[it]);
     259        }
     260
    249261
    250262        class Pointer {
    251263          friend class const_iterator;
    252264        private:
    253           typedef extended_pair<const Key&, const Key&, const Value&, const Value&> Pair;
    254           Pair data;
     265          Reference data;
    255266          Pointer(const Key& key, const Value& val) : data(key, val) {}
    256267        public:
    257           Pair* operator->() {return &data;}
     268          Reference* operator->() {return &data;}
    258269        };
     270
    259271        /** Arrow operator for map.
    260272         */     
    261         Pointer operator->() const {
    262           return Pointer(it, (*map)[it]);
     273        Pointer operator->() {
     274          return Pointer(it, ((*map)[it]));
    263275        }
    264276
Note: See TracChangeset for help on using the changeset viewer.