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