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