src/work/deba/vector_map.h
changeset 538 d8863141824d
parent 377 33fe0ee01dc5
equal deleted inserted replaced
1:c5c65932b791 2:4a5b40dc2f26
     1 #ifndef VECTOR_MAP_H
     1 #ifndef VECTOR_MAP_H
     2 #define VECTOR_MAP_H
     2 #define VECTOR_MAP_H
     3 
     3 
     4 #include <vector>
     4 #include <vector>
       
     5 #include <iostream>
     5 
     6 
     6 template <typename G, typename K, typename V, template <typename, typename> class MapBase > 
     7 #include "map_base.h"
     7 class VectorMap : public MapBase<G, K> {
     8 
     8 public:
     9 namespace hugo {
     9 	typedef V ValueType;
    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;
    10 	
    15 	
    11 	VectorMap() {}
    16 		VectorMap() {}
    12 	VectorMap(G& g) : MapBase<G, K>(g) {
    17 		VectorMap(typename MapBase<G, K, KIt>::Registry& r) : MapBase<G, K, KIt>(r) {}
    13 		init();
       
    14 	}
       
    15 	
    18 	
    16 	~VectorMap() {
       
    17 //		destroy();
       
    18 	} 
       
    19 	
    19 	
    20 	ValueType& operator[](const K& key) {
    20 		ValueType& operator[](const K& key) {
    21 		return container[key->id];
    21 			int id = registry->getGraph().id(key);
    22 	} 
    22 			return container[id];
       
    23 		} 
    23 	
    24 	
    24 	const ValueType& operator[](const K& key) const {
    25 		const ValueType& operator[](const K& key) const {
    25 		return container[key->id];
    26 			int id = registry->getGraph().id(key);
    26 	}
    27 			return container[id];
       
    28 		}
    27 	
    29 	
    28 	const ValueType& get(const K& key) const {
    30 		const ValueType& get(const K& key) const {
    29 		return container[key->id];
    31 			int id = registry->getGraph().id(key);
    30 	} 
    32 			return container[id];
       
    33 		} 
    31 	
    34 	
    32 	void set(const K& key, const ValueType& val) {
    35 		void set(const K& key, const ValueType& val) {
    33 		container[key->id] = val;
    36 			int id = registry->getGraph().id(key);
    34 	}
    37 			container[id] = val;
       
    38 		}
    35 	
    39 	
    36 	void add(const K& key) {
    40 		void add(const K& key) {
    37 		if (key->id() >= container.size()) {
    41 			int id = registry->getGraph().id(key);
    38 			container.resize(key->id() + 1);
    42 			std::cerr << id << std::endl;
       
    43 			if (id >= container.size()) {
       
    44 				container.resize(id + 1);
       
    45 			}
    39 		}
    46 		}
    40 	}
       
    41 	
    47 	
    42 	void erase(const K& key) {}
    48 		void erase(const K& key) {}
    43 
    49 
    44 private:
    50 	private:
    45 	typedef std::vector<ValueType> Container;
    51 		typedef std::vector<ValueType> Container;
    46 	
    52 	
    47 	Container container;
    53 		Container container;
    48 };
    54 	};
       
    55 
       
    56 }
    49 
    57 
    50 #endif
    58 #endif