Changeset 378:c3f93631cd24 in lemon-0.x for src/work
- Timestamp:
- 04/22/04 22:36:21 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@508
- Location:
- src/work/deba
- Files:
-
- 4 added
- 5 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/deba/test_graph.h
r377 r378 8 8 #include "invalid.h" 9 9 10 #include "edge_map_registry.h"11 #include "node_map_registry.h"12 #include "edge_map_base.h"13 #include "node_map_base.h"14 10 #include "vector_map.h" 15 11 … … 43 39 private: 44 40 45 NodeMapRegistry<ListGraph, Node> node_maps(*this); 46 EdgeMapRegistry<ListGraph, Edge> edge_maps(*this); 41 typedef MapRegistry<ListGraph, Node, NodeIt> NodeMapRegistry; 42 NodeMapRegistry node_maps; 43 44 typedef MapRegistry<ListGraph, Edge, EdgeIt> EdgeMapRegistry; 45 EdgeMapRegistry edge_maps; 47 46 48 47 public: … … 50 49 51 50 template <typename T> 52 class NodeMap : public VectorMap<ListGraph, Node, T, NodeMapBase> {51 class NodeMap : public VectorMap<ListGraph, Node, NodeIt, T> { 53 52 public: 54 NodeMap(ListGraph& g) : VectorMap<ListGraph, Node, T, NodeMapBase>(g) {}53 NodeMap(ListGraph& g) : VectorMap<ListGraph, Node, NodeIt, T>(g.node_maps) {} 55 54 }; 56 55 57 EdgeMapRegistry<ListGraph, Edge> edge_maps;58 59 56 template <typename T> 60 class EdgeMap : public VectorMap<ListGraph, Edge, T, EdgeMapBase> {}; 57 class EdgeMap : public VectorMap<ListGraph, Edge, EdgeIt, T> { 58 public: 59 EdgeMap(ListGraph& g) : VectorMap<ListGraph, Edge, EdgeIt, T>(g.edge_maps) {} 60 }; 61 61 62 62 … … 216 216 /* default constructor */ 217 217 218 ListGraph() : node_id(0), edge_id(0), _node_num(0), _edge_num(0), _first_node(0), _last_node(0) { } 218 ListGraph() : node_id(0), edge_id(0), _node_num(0), _edge_num(0), _first_node(0), _last_node(0), 219 edge_maps(*this), node_maps(*this) { } 219 220 220 221 ~ListGraph() { -
src/work/deba/vector_map.h
r377 r378 3 3 4 4 #include <vector> 5 #include <iostream> 5 6 6 template <typename G, typename K, typename V, template <typename, typename> class MapBase > 7 class VectorMap : public MapBase<G, K> { 8 public: 9 typedef V ValueType; 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; 10 15 11 VectorMap() {} 12 VectorMap(G& g) : MapBase<G, K>(g) { 13 init(); 14 } 16 VectorMap() {} 17 VectorMap(typename MapBase<G, K, KIt>::Registry& r) : MapBase<G, K, KIt>(r) {} 15 18 16 ~VectorMap() {17 // destroy();18 }19 19 20 ValueType& operator[](const K& key) { 21 return container[key->id]; 22 } 20 ValueType& operator[](const K& key) { 21 int id = registry->getGraph().id(key); 22 return container[id]; 23 } 23 24 24 const ValueType& operator[](const K& key) const { 25 return container[key->id]; 26 } 25 const ValueType& operator[](const K& key) const { 26 int id = registry->getGraph().id(key); 27 return container[id]; 28 } 27 29 28 const ValueType& get(const K& key) const { 29 return container[key->id]; 30 } 30 const ValueType& get(const K& key) const { 31 int id = registry->getGraph().id(key); 32 return container[id]; 33 } 31 34 32 void set(const K& key, const ValueType& val) { 33 container[key->id] = val; 34 } 35 void set(const K& key, const ValueType& val) { 36 int id = registry->getGraph().id(key); 37 container[id] = val; 38 } 35 39 36 void add(const K& key) { 37 if (key->id() >= container.size()) { 38 container.resize(key->id() + 1); 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 } 39 46 } 40 }41 47 42 void erase(const K& key) {}48 void erase(const K& key) {} 43 49 44 private:45 typedef std::vector<ValueType> Container;50 private: 51 typedef std::vector<ValueType> Container; 46 52 47 Container container; 48 }; 53 Container container; 54 }; 55 56 } 49 57 50 58 #endif
Note: See TracChangeset
for help on using the changeset viewer.