Changeset 340:a2ce3c4780b7 in lemon0.x for src/work/deba/test_graph.h
 Timestamp:
 04/16/04 15:42:03 (19 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@459
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

src/work/deba/test_graph.h
r262 r340 7 7 8 8 #include <invalid.h> 9 10 #include "vector_map.h" 11 #include "edge_map_registry.h" 12 #include "node_map_registry.h" 13 #include "edge_map_base.h" 14 #include "node_map_base.h" 9 15 10 16 namespace hugo { … … 29 35 class SymEdgeIt; 30 36 31 template <typename T> class NodeMap;32 template <typename T> class EdgeMap;37 // template <typename T> class NodeMap; 38 // template <typename T> class EdgeMap; 33 39 private: 34 template <typename T> friend class NodeMap;35 template <typename T> friend class EdgeMap;40 // template <typename T> friend class NodeMap; 41 // template <typename T> friend class EdgeMap; 36 42 43 NodeMapRegistry<ListGraph, Node> node_maps; 44 37 45 template <typename T> 38 class NodeMap { 39 const ListGraph& G; 40 std::vector<T> container; 41 public: 42 typedef T ValueType; 43 typedef Node KeyType; 44 NodeMap(const ListGraph& _G) : G(_G), container(G.node_id) { } 45 NodeMap(const ListGraph& _G, T a) : 46 G(_G), container(G.node_id, a) { } 47 void set(Node n, T a) { container[/*G.id(n)*/n.node>id]=a; } 48 T get(Node n) const { return container[/*G.id(n)*/n.node>id]; } 49 typename std::vector<T>::reference operator[](Node n) { 50 return container[/*G.id(n)*/n.node>id]; } 51 typename std::vector<T>::const_reference operator[](Node n) const { 52 return container[/*G.id(n)*/n.node>id]; 53 } 54 void update() { container.resize(G.node_id); } 55 void update(T a) { container.resize(G.node_id, a); } 56 }; 46 class NodeMap : public VectorMap<ListGraph, Edge, T, EdgeMapBase> {}; 47 48 EdgeMapRegistry<ListGraph, Edge> edge_maps; 57 49 58 50 template <typename T> 59 class EdgeMap { 60 const ListGraph& G; 61 std::vector<T> container; 62 public: 63 typedef T ValueType; 64 typedef Edge KeyType; 65 EdgeMap(const ListGraph& _G) : G(_G), container(G.edge_id) { } 66 EdgeMap(const ListGraph& _G, T a) : 67 G(_G), container(G.edge_id, a) { } 68 void set(Edge e, T a) { container[/*G.id(e)*/e.edge>id]=a; } 69 T get(Edge e) const { return container[/*G.id(e)*/e.edge>id]; } 70 typename std::vector<T>::reference operator[](Edge e) { 71 return container[/*G.id(e)*/e.edge>id]; } 72 typename std::vector<T>::const_reference operator[](Edge e) const { 73 return container[/*G.id(e)*/e.edge>id]; 74 } 75 void update() { container.resize(G.edge_id); } 76 void update(T a) { container.resize(G.edge_id, a); } 77 }; 51 class EdgeMap : public VectorMap<Graph, Node, T, NodeMapBase> {}; 52 78 53 79 54 int node_id; … … 324 299 /* adding nodes and edges */ 325 300 326 Node addNode() { return Node(_add_node()); } 301 Node addNode() { 302 Node n = _add_node(); 303 node_maps.add(n); 304 return n; 305 } 327 306 Edge addEdge(Node u, Node v) { 328 return Edge(_add_edge(u.node, v.node)); 307 Edge e = _add_edge(u.node, v.node); 308 edge_maps.add(e); 309 return e; 329 310 } 330 311 331 312 void erase(Node i) { 313 node_map.erase(i); 332 314 while (first<OutEdgeIt>(i).valid()) erase(first<OutEdgeIt>(i)); 333 315 while (first<InEdgeIt>(i).valid()) erase(first<InEdgeIt>(i)); … … 335 317 } 336 318 337 void erase(Edge e) { _delete_edge(e.edge); } 319 void erase(Edge e) { 320 edge_maps.erase(e); 321 _delete_edge(e.edge); 322 } 338 323 339 324 void clear() {
Note: See TracChangeset
for help on using the changeset viewer.