src/work/deba/vector_map_factory.h
changeset 597 a6e2b02f496a
parent 571 9632ea8be6ca
child 627 6cc21a9c9fda
equal deleted inserted replaced
0:0ddc9fffebb3 1:d068dfc4078a
     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>
       
     6 
     5 
     7 #include "map_base.h"
     6 #include "map_base.h"
     8 
     7 
     9 namespace hugo {
     8 namespace hugo {
    10 	
     9 	
    17 		typedef G Graph;
    16 		typedef G Graph;
    18 		typedef K Key;
    17 		typedef K Key;
    19 		typedef KIt KeyIt;
    18 		typedef KIt KeyIt;
    20 		
    19 		
    21 		template <typename V> 
    20 		template <typename V> 
    22 		class VectorMap : public MapBase<G, K, KIt> {
    21 		class Map : public MapBase<G, K, KIt> {
    23 		public:
    22 		public:
    24 			typedef V ValueType;
    23 			typedef V Value;
    25 	
    24 	
    26 			VectorMap() {}
    25 			Map() {}
    27 			
    26 			
    28 			VectorMap(Graph& g, MapRegistry<G, K, KIt>& r) 
    27 			Map(Graph& g, MapRegistry<G, K, KIt>& r) 
    29 				: MapBase<G, K, KIt>(g, r) {}
    28 				: MapBase<G, K, KIt>(g, r) {
       
    29 				init();
       
    30 			}
       
    31 				
       
    32 			virtual ~Map() {
       
    33 				destroy();
       
    34 			}
    30 	
    35 	
    31 	
    36 	
    32 			ValueType& operator[](const K& key) {
    37 			Value& operator[](const K& key) {
    33 				int id = graph->id(key);
    38 				int id = graph->id(key);
    34 				return container[id];
    39 				return container[id];
    35 			} 
    40 			} 
    36 		
    41 		
    37 			const ValueType& operator[](const K& key) const {
    42 			const Value& operator[](const K& key) const {
    38 				int id = graph->id(key);
    43 				int id = graph->id(key);
    39 				return container[id];
    44 				return container[id];
    40 			}
    45 			}
    41 	
    46 	
    42 			const ValueType& get(const K& key) const {
    47 			const Value& get(const K& key) const {
    43 				int id = graph->id(key);
    48 				int id = graph->id(key);
    44 				return container[id];
    49 				return container[id];
    45 			} 
    50 			} 
    46 		
    51 		
    47 			void set(const K& key, const ValueType& val) {
    52 			void set(const K& key, const Value& val) {
    48 				int id = graph->id(key);
    53 				int id = graph->id(key);
    49 				container[id] = val;
    54 				container[id] = val;
    50 			}
    55 			}
    51 		
    56 		
    52 			void add(const K& key) {
    57 			void add(const K& key) {
    53 				int id = graph->id(key);
    58 				int id = graph->id(key);
    54 				std::cerr << id << std::endl;
       
    55 				if (id >= container.size()) {
    59 				if (id >= container.size()) {
    56 					container.resize(id + 1);
    60 					container.resize(id + 1);
    57 				}
    61 				}
    58 			}
    62 			}
    59 		
    63 		
    60 			void erase(const K& key) {}
    64 			void erase(const K& key) {}
    61 	
    65 	
    62 		private:
    66 		private:
    63 			typedef std::vector<ValueType> Container;
    67 			typedef std::vector<Value> Container;
    64 		
    68 		
    65 			Container container;
    69 			Container container;
    66 		};
    70 		};
    67 		
    71 		
    68 	};
    72 	};