Changeset 595:e10b5e9419ef in lemon-0.x for src/work/deba
- Timestamp:
- 05/10/04 15:49:35 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@775
- Location:
- src/work/deba
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/deba/main.cpp
r571 r595 1 1 #include <iostream> 2 #include <cstdlib> 2 3 #include "test_graph.h" 3 4 … … 8 9 int main() { 9 10 ListGraph g; 10 ListGraph::NodeMapFactory::VectorMap<int> map(g, g.node_maps); 11 ListGraph::Node node = g.addNode(); 12 map[node] = 12; 11 for (int i = 0; i < 3; ++i) { 12 ListGraph::Node node = g.addNode(); 13 } 14 ListGraph::NodeMapFactory::Map<int> map(g, g.node_maps); 15 for (int i = 0; i < 10; ++i) { 16 ListGraph::Node node = g.addNode(); 17 map[node] = rand()%100; 18 } 19 for (ListGraph::NodeIt it(g); g.valid(it); g.next(it)) { 20 cout << map[it] << endl; 21 } 13 22 return 0; 14 23 } -
src/work/deba/map_base.h
r571 r595 2 2 #define MAP_BASE_H 3 3 4 using namespace std; 5 4 6 /** 5 Template base class for implementing mapping on nodes .6 \param The first template parameter is the Graph class. The Graph7 must have an \emp node_maps member with \emp MapRegistry class.8 \param The second template parameter is the type of the class.9 7 Template base class for implementing mapping on nodes and edges. 8 \param The first template parameter is the Graph class. 9 \param The second template parameter is the key type. 10 \param The third template parameter is an iterator on 11 the keys. 10 12 */ 11 13 … … 25 27 typedef G Graph; 26 28 typedef MapRegistry<G, K, KIt> Registry; 27 typedef K Key Type;29 typedef K Key; 28 30 typedef KIt KeyIt; 29 31 … … 34 36 */ 35 37 36 MapBase() : registry(0) {}38 MapBase() : graph(0), registry(0) {} 37 39 38 40 /** … … 41 43 42 44 MapBase(Graph& g, Registry& r) : graph(&g), registry(0) { 43 r egistry->attach(*this);45 r.attach(*this); 44 46 } 45 47 … … 81 83 protected: 82 84 85 Graph* graph; 83 86 Registry* registry; 84 Graph* graph;85 87 86 88 int registry_index; 87 89 88 90 /** 89 Helper function to implement the default constructorin the subclasses.91 Helper function to implement constructors in the subclasses. 90 92 */ 91 93 92 94 virtual void init() { 93 94 95 for (KeyIt it(*graph); graph->valid(it); graph->next(it)) { 95 96 add(it); … … 112 113 */ 113 114 114 virtual void add(const KeyType&) = 0; 115 115 virtual void add(const Key&) = 0; 116 116 /** 117 117 The erase member function should be overloaded in the subclasses. … … 119 119 */ 120 120 121 virtual void erase(const Key Type&) = 0;121 virtual void erase(const Key&) = 0; 122 122 123 123 /** -
src/work/deba/map_registry.h
r571 r595 3 3 4 4 #include <vector> 5 6 using namespace std; 5 7 6 8 … … 63 65 map.registry = this; 64 66 map.registry_index = container.size()-1; 65 map.init();66 67 } 67 68 68 void detach(Map& map_base) { 69 map_base.destroy(); 70 container.back()->registry_index = map_base.registry_index; 71 container[map_base.registry_index] = container.back(); 69 void detach(Map& map) { 70 container.back()->registry_index = map.registry_index; 71 container[map.registry_index] = container.back(); 72 72 container.pop_back(); 73 map _base.registry = 0;74 map _base.graph = 0;73 map.registry = 0; 74 map.graph = 0; 75 75 } 76 76 77 77 78 v oid add(Key& key) {78 virtual void add(Key& key) { 79 79 typename Container::iterator it; 80 80 for (it = container.begin(); it != container.end(); ++it) { … … 83 83 } 84 84 85 v oid erase(Key& key) {85 virtual void erase(Key& key) { 86 86 typename Container::iterator it; 87 87 for (it = container.begin(); it != container.end(); ++it) { -
src/work/deba/test_graph.h
r571 r595 42 42 public: 43 43 44 typedef MapBase<ListGraph, Node, NodeIt> NodeMapBase; 44 45 typedef MapRegistry<ListGraph, Node, NodeIt> NodeMapRegistry; 46 typedef VectorMapFactory<ListGraph, Node, NodeIt> NodeMapFactory; 45 47 NodeMapRegistry node_maps; 46 47 48 49 50 51 typedef MapBase<ListGraph, Edge, EdgeIt> EdgeMapBase; 48 52 typedef MapRegistry<ListGraph, Edge, EdgeIt> EdgeMapRegistry; 53 typedef VectorMapFactory<ListGraph, Edge, EdgeIt> EdgeMapFactory; 49 54 EdgeMapRegistry edge_maps; 50 51 typedef VectorMapFactory<ListGraph, Edge, EdgeIt> EdgeMapFactory;52 typedef VectorMapFactory<ListGraph, Node, NodeIt> NodeMapFactory;53 55 54 56 -
src/work/deba/vector_map_factory.h
r571 r595 3 3 4 4 #include <vector> 5 #include <iostream>6 5 7 6 #include "map_base.h" … … 20 19 21 20 template <typename V> 22 class VectorMap : public MapBase<G, K, KIt> {21 class Map : public MapBase<G, K, KIt> { 23 22 public: 24 typedef V Value Type;23 typedef V Value; 25 24 26 VectorMap() {}25 Map() {} 27 26 28 VectorMap(Graph& g, MapRegistry<G, K, KIt>& r) 29 : MapBase<G, K, KIt>(g, r) {} 27 Map(Graph& g, MapRegistry<G, K, KIt>& r) 28 : MapBase<G, K, KIt>(g, r) { 29 init(); 30 } 31 32 virtual ~Map() { 33 destroy(); 34 } 30 35 31 36 32 Value Type& operator[](const K& key) {37 Value& operator[](const K& key) { 33 38 int id = graph->id(key); 34 39 return container[id]; 35 40 } 36 41 37 const Value Type& operator[](const K& key) const {42 const Value& operator[](const K& key) const { 38 43 int id = graph->id(key); 39 44 return container[id]; 40 45 } 41 46 42 const Value Type& get(const K& key) const {47 const Value& get(const K& key) const { 43 48 int id = graph->id(key); 44 49 return container[id]; 45 50 } 46 51 47 void set(const K& key, const Value Type& val) {52 void set(const K& key, const Value& val) { 48 53 int id = graph->id(key); 49 54 container[id] = val; … … 52 57 void add(const K& key) { 53 58 int id = graph->id(key); 54 std::cerr << id << std::endl;55 59 if (id >= container.size()) { 56 60 container.resize(id + 1); … … 61 65 62 66 private: 63 typedef std::vector<Value Type> Container;67 typedef std::vector<Value> Container; 64 68 65 69 Container container;
Note: See TracChangeset
for help on using the changeset viewer.