diff -r 768ebc700bae -r a2ce3c4780b7 src/work/deba/test_graph.h --- a/src/work/deba/test_graph.h Fri Apr 16 13:26:15 2004 +0000 +++ b/src/work/deba/test_graph.h Fri Apr 16 13:42:03 2004 +0000 @@ -7,6 +7,12 @@ #include +#include "vector_map.h" +#include "edge_map_registry.h" +#include "node_map_registry.h" +#include "edge_map_base.h" +#include "node_map_base.h" + namespace hugo { template @@ -28,53 +34,22 @@ class InEdgeIt; class SymEdgeIt; - template class NodeMap; - template class EdgeMap; +// template class NodeMap; +// template class EdgeMap; private: - template friend class NodeMap; - template friend class EdgeMap; +// template friend class NodeMap; + // template friend class EdgeMap; - template - class NodeMap { - const ListGraph& G; - std::vector container; - public: - typedef T ValueType; - typedef Node KeyType; - NodeMap(const ListGraph& _G) : G(_G), container(G.node_id) { } - NodeMap(const ListGraph& _G, T a) : - G(_G), container(G.node_id, a) { } - void set(Node n, T a) { container[/*G.id(n)*/n.node->id]=a; } - T get(Node n) const { return container[/*G.id(n)*/n.node->id]; } - typename std::vector::reference operator[](Node n) { - return container[/*G.id(n)*/n.node->id]; } - typename std::vector::const_reference operator[](Node n) const { - return container[/*G.id(n)*/n.node->id]; - } - void update() { container.resize(G.node_id); } - void update(T a) { container.resize(G.node_id, a); } - }; + NodeMapRegistry node_maps; template - class EdgeMap { - const ListGraph& G; - std::vector container; - public: - typedef T ValueType; - typedef Edge KeyType; - EdgeMap(const ListGraph& _G) : G(_G), container(G.edge_id) { } - EdgeMap(const ListGraph& _G, T a) : - G(_G), container(G.edge_id, a) { } - void set(Edge e, T a) { container[/*G.id(e)*/e.edge->id]=a; } - T get(Edge e) const { return container[/*G.id(e)*/e.edge->id]; } - typename std::vector::reference operator[](Edge e) { - return container[/*G.id(e)*/e.edge->id]; } - typename std::vector::const_reference operator[](Edge e) const { - return container[/*G.id(e)*/e.edge->id]; - } - void update() { container.resize(G.edge_id); } - void update(T a) { container.resize(G.edge_id, a); } - }; + class NodeMap : public VectorMap {}; + + EdgeMapRegistry edge_maps; + + template + class EdgeMap : public VectorMap {}; + int node_id; int edge_id; @@ -323,18 +298,28 @@ /* adding nodes and edges */ - Node addNode() { return Node(_add_node()); } + Node addNode() { + Node n = _add_node(); + node_maps.add(n); + return n; + } Edge addEdge(Node u, Node v) { - return Edge(_add_edge(u.node, v.node)); + Edge e = _add_edge(u.node, v.node); + edge_maps.add(e); + return e; } void erase(Node i) { + node_map.erase(i); while (first(i).valid()) erase(first(i)); while (first(i).valid()) erase(first(i)); _delete_node(i.node); } - void erase(Edge e) { _delete_edge(e.edge); } + void erase(Edge e) { + edge_maps.erase(e); + _delete_edge(e.edge); + } void clear() { while (first().valid()) erase(first());