Rev | Line | |
---|
[340] | 1 | #ifndef VECTOR_MAP_H |
---|
| 2 | #define VECTOR_MAP_H |
---|
| 3 | |
---|
| 4 | #include <vector> |
---|
[378] | 5 | #include <iostream> |
---|
[340] | 6 | |
---|
[378] | 7 | #include "map_base.h" |
---|
| 8 | |
---|
| 9 | namespace hugo { |
---|
| 10 | |
---|
| 11 | template <typename G, typename K, typename KIt, typename V> |
---|
| 12 | class VectorMap : public MapBase<G, K, KIt> { |
---|
| 13 | public: |
---|
| 14 | typedef V ValueType; |
---|
[340] | 15 | |
---|
[378] | 16 | VectorMap() {} |
---|
| 17 | VectorMap(typename MapBase<G, K, KIt>::Registry& r) : MapBase<G, K, KIt>(r) {} |
---|
[340] | 18 | |
---|
| 19 | |
---|
[378] | 20 | ValueType& operator[](const K& key) { |
---|
| 21 | int id = registry->getGraph().id(key); |
---|
| 22 | return container[id]; |
---|
| 23 | } |
---|
[340] | 24 | |
---|
[378] | 25 | const ValueType& operator[](const K& key) const { |
---|
| 26 | int id = registry->getGraph().id(key); |
---|
| 27 | return container[id]; |
---|
| 28 | } |
---|
[340] | 29 | |
---|
[378] | 30 | const ValueType& get(const K& key) const { |
---|
| 31 | int id = registry->getGraph().id(key); |
---|
| 32 | return container[id]; |
---|
| 33 | } |
---|
[340] | 34 | |
---|
[378] | 35 | void set(const K& key, const ValueType& val) { |
---|
| 36 | int id = registry->getGraph().id(key); |
---|
| 37 | container[id] = val; |
---|
| 38 | } |
---|
[340] | 39 | |
---|
[378] | 40 | void add(const K& key) { |
---|
| 41 | int id = registry->getGraph().id(key); |
---|
| 42 | std::cerr << id << std::endl; |
---|
| 43 | if (id >= container.size()) { |
---|
| 44 | container.resize(id + 1); |
---|
| 45 | } |
---|
[377] | 46 | } |
---|
[340] | 47 | |
---|
[378] | 48 | void erase(const K& key) {} |
---|
[340] | 49 | |
---|
[378] | 50 | private: |
---|
| 51 | typedef std::vector<ValueType> Container; |
---|
[340] | 52 | |
---|
[378] | 53 | Container container; |
---|
| 54 | }; |
---|
| 55 | |
---|
| 56 | } |
---|
[340] | 57 | |
---|
| 58 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.