COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/deba/vector_map_factory.h @ 618:e944d741f472

Last change on this file since 618:e944d741f472 was 595:e10b5e9419ef, checked in by Balazs Dezso, 20 years ago
File size: 1.2 KB
RevLine 
[571]1#ifndef VECTOR_MAP_H
2#define VECTOR_MAP_H
3
4#include <vector>
5
6#include "map_base.h"
7
8namespace hugo {
9       
10        template <typename G, typename K, typename KIt>
11        class VectorMapFactory {
12       
13       
14        public:
15               
16                typedef G Graph;
17                typedef K Key;
18                typedef KIt KeyIt;
19               
20                template <typename V>
[595]21                class Map : public MapBase<G, K, KIt> {
[571]22                public:
[595]23                        typedef V Value;
[571]24       
[595]25                        Map() {}
[571]26                       
[595]27                        Map(Graph& g, MapRegistry<G, K, KIt>& r)
28                                : MapBase<G, K, KIt>(g, r) {
29                                init();
30                        }
31                               
32                        virtual ~Map() {
33                                destroy();
34                        }
[571]35       
36       
[595]37                        Value& operator[](const K& key) {
[571]38                                int id = graph->id(key);
39                                return container[id];
40                        }
41               
[595]42                        const Value& operator[](const K& key) const {
[571]43                                int id = graph->id(key);
44                                return container[id];
45                        }
46       
[595]47                        const Value& get(const K& key) const {
[571]48                                int id = graph->id(key);
49                                return container[id];
50                        }
51               
[595]52                        void set(const K& key, const Value& val) {
[571]53                                int id = graph->id(key);
54                                container[id] = val;
55                        }
56               
57                        void add(const K& key) {
58                                int id = graph->id(key);
59                                if (id >= container.size()) {
60                                        container.resize(id + 1);
61                                }
62                        }
63               
64                        void erase(const K& key) {}
65       
66                private:
[595]67                        typedef std::vector<Value> Container;
[571]68               
69                        Container container;
70                };
71               
72        };
73}
74
75#endif
Note: See TracBrowser for help on using the repository browser.