# HG changeset patch # User deba # Date 1082651817 0 # Node ID 33fe0ee01dc5c5beb51bea1fd67eed885f388caa # Parent 5c12f35154528f231df649c72e3b2ec83a6541e8 diff -r 5c12f3515452 -r 33fe0ee01dc5 src/work/deba/edge_map_base.h --- a/src/work/deba/edge_map_base.h Thu Apr 22 16:07:17 2004 +0000 +++ b/src/work/deba/edge_map_base.h Thu Apr 22 16:36:57 2004 +0000 @@ -11,8 +11,12 @@ template class EdgeMapBase { + +#include "edge_map_registry.h" + public: typedef G Graph; + friend class EdgeMapRegistry; typedef K KeyType; @@ -77,7 +81,7 @@ */ void init() { - for (Graph::EdgeIt it(g); g.valid(it); g.next(it)) { + for (typename Graph::EdgeIt it(g); g.valid(it); g.next(it)) { add(it); } } @@ -87,7 +91,7 @@ */ void destroy() { - for (Graph::EdgeIt it(g); g.valid(it); g.next(it)) { + for (typename Graph::EdgeIt it(g); g.valid(it); g.next(it)) { erase(it); } } @@ -112,7 +116,6 @@ class NotSupportedOperationException {}; - friend class Graph; }; #endif diff -r 5c12f3515452 -r 33fe0ee01dc5 src/work/deba/edge_map_register.h --- a/src/work/deba/edge_map_register.h Thu Apr 22 16:07:17 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -#ifndef EDGE_MAP_REGISTER_H -#define EDGE_MAP_REGISTER_H - -#include - -template -class EdgeMapRegister { -public: - typedef G Graph; - typedef E Edge - - typedef EdgeMapBase EdgeMapBase; - -protected: - typedef std::vector Container; - - Container container; - - void add(EdgeMapBase& map_base) { - if (map_base.graph) { - map_base.graph->edge_maps.erase(map_base); - } - container.push_back(&map_base); - map_base.graph_index = container.size()-1; - } - - void erase(EdgeMapBase& map_base) { - if (map_base.graph != this) return; - container.back()->graph_index = map_base.graph_index; - container[map_base.graph_index] = container.back(); - container.pop_back(); - map_base.graph = 0; - } - - void addEdge(Edge& edge) { - typename Container::iterator it; - for (it = container.begin(); it != container.end(); ++it) { - (*it)->add(edge); - } - } - - void eraseEdge(Edge& edge) { - typename Container::iterator it; - for (it = container.begin(); it != container.end(); ++it) { - (*it)->erase(edge); - } - } - - friend class EdgeMapBase; -}; - -#endif diff -r 5c12f3515452 -r 33fe0ee01dc5 src/work/deba/edge_map_registry.h --- a/src/work/deba/edge_map_registry.h Thu Apr 22 16:07:17 2004 +0000 +++ b/src/work/deba/edge_map_registry.h Thu Apr 22 16:36:57 2004 +0000 @@ -3,37 +3,48 @@ #include +template +class EdgeMapRegistry; + #include "edge_map_base.h" -template +template class EdgeMapRegistry { public: typedef G Graph; - typedef E Edge + typedef K Edge; typedef EdgeMapBase MapBase; + friend class MapBase; protected: - typedef std::vector Container; + + Graph* graph; + + typedef std::vector Container; Container container; - + +public: + + EdgeMapRegistry(Graph g) : graph(&g) {} + void add(MapBase& map_base) { if (map_base.graph) { map_base.graph->edge_maps.erase(map_base); } container.push_back(&map_base); - map_base.graph = this; + map_base.graph = graph; map_base.graph_index = container.size()-1; } void erase(MapBase& map_base) { - if (map_base.graph != this) return; container.back()->graph_index = map_base.graph_index; container[map_base.graph_index] = container.back(); container.pop_back(); map_base.graph = 0; } + void add(Edge& edge) { typename Container::iterator it; @@ -49,7 +60,6 @@ } } - friend class MapBase; }; #endif diff -r 5c12f3515452 -r 33fe0ee01dc5 src/work/deba/mapbase.h --- a/src/work/deba/mapbase.h Thu Apr 22 16:07:17 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -#ifndef MAPBASE_H -#define MAPBASE_H - -template -class MapBase { -public: - typedef GB GraphBase; - typedef MappedGraph Graph; - - typedef K KeyType; - - - MapBase() : graph(0) {} - MapBase(Graph& g) : graph(&g) {graph.add(*this);} - - virtual ~MapBase() {graph.erase(*this);} - -protected: - - Graph* graph; - - int graph_index; - - - virtual void add(const KeyType&) = 0; - virtual void erase(const KeyType&) = 0; - - friend class Graph; -}; - -#endif diff -r 5c12f3515452 -r 33fe0ee01dc5 src/work/deba/mappedgraph.h --- a/src/work/deba/mappedgraph.h Thu Apr 22 16:07:17 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -#ifndef MAPPEDGRAPH_H -#define MAPPEDGRAPH_H - -#include - -template -class MapBase; - -template -class MappedGraph : public GB { -public: - typedef GB GraphBase; - - typedef MapBase EdgeMapBase; - typedef MapBase NodeMapBase; - -protected: - typedef std::vector EdgeMaps; - typedef std::vector NodeMaps; - - EdgeMaps edge_maps; - NodeMaps node_maps; - - void add(EdgeMapBase& map_base) { - if (map_base.graph) { - map_base.graph->erase(map_base); - } - edge_maps.push_back(&map_base); - map_base.graph_index = map_base.size()-1; - } - - void erase(EdgeMapBase& map_base) { - if (map_base.graph != this) return; - edge_maps.back()->graph_index = map_base.graph_index; - edge_maps[map_base.graph_index] = edge_maps.back(); - edge_maps.pop_back(); - map_base.graph = 0; - } - - void addEdge(typename GB::Edge& edge) { - typename EdgeMaps::iterator it; - for (it = edge_maps.begin(); it != edge_maps.end(); ++it) { - (*it)->add(edge); - } - } - - void eraseEdge(typename GB::Edge& edge) { - typename EdgeMaps::iterator it; - for (it = edge_maps.begin(); it != edge_maps.end(); ++it) { - (*it)->erase(edge); - } - } - - void add(NodeMapBase& map_base) { - if (map_base.graph) { - map_base.graph->erase(map_base); - } - node_maps.push_back(&map_base); - map_base.graph_index = node_maps.size()-1; - } - - void erase(NodeMapBase& map_base) { - if (map_base.graph != this) return; - node_maps.back()->graph_index = map_base.graph_index; - node_maps[map_base.graph_index] = node_maps.back(); - node_maps.pop_back(); - map_base.graph = 0; - } - - void addNode(typename GB::Node& node) { - typename NodeMaps::iterator it; - for (it = node_maps.begin(); it != node_maps.end(); ++it) { - (*it)->add(node); - } - } - - void eraseNode(typename GB::Node& node) { - typename NodeMaps::iterator it; - for (it = node_maps.begin(); it != node_maps.end(); ++it) { - (*it)->erase(node); - } - } - - friend class EdgeMapBase; - friend class NodeMapBase; -}; - -#endif diff -r 5c12f3515452 -r 33fe0ee01dc5 src/work/deba/node_map_base.h --- a/src/work/deba/node_map_base.h Thu Apr 22 16:07:17 2004 +0000 +++ b/src/work/deba/node_map_base.h Thu Apr 22 16:36:57 2004 +0000 @@ -11,8 +11,12 @@ template class NodeMapBase { + +#include "node_map_registry.h" + public: typedef G Graph; + friend class NodeMapRegistry; typedef K KeyType; @@ -62,7 +66,7 @@ virtual ~NodeMapBase() { if (graph) { - graph.node_maps.erase(*this); + graph->node_maps.erase(*this); } } @@ -77,7 +81,7 @@ */ void init() { - for (Graph::NodeIt it(g); g.valid(it); g.next(it)) { + for (typename Graph::NodeIt it(g); g.valid(it); g.next(it)) { add(it); } } @@ -87,7 +91,7 @@ */ void destroy() { - for (Graph::NodeIt it(g); g.valid(it); g.next(it)) { + for (typename Graph::NodeIt it(g); g.valid(it); g.next(it)) { erase(it); } } @@ -112,7 +116,6 @@ class NotSupportedOperationException {}; - friend class Graph; }; #endif diff -r 5c12f3515452 -r 33fe0ee01dc5 src/work/deba/node_map_registry.h --- a/src/work/deba/node_map_registry.h Thu Apr 22 16:07:17 2004 +0000 +++ b/src/work/deba/node_map_registry.h Thu Apr 22 16:36:57 2004 +0000 @@ -3,37 +3,48 @@ #include +template +class NodeMapRegistry; + #include "node_map_base.h" -template +template class NodeMapRegistry { public: typedef G Graph; - typedef E Node + typedef K Node; - typedef NodeMapBase NodeMapBase; + typedef NodeMapBase MapBase; + friend class MapBase; protected: - typedef std::vector Container; + + Graph* graph; + + typedef std::vector Container; Container container; - - void add(NodeMapBase& map_base) { + +public: + + NodeMapRegistry(Graph g) : graph(&g) {} + + void add(MapBase& map_base) { if (map_base.graph) { map_base.graph->node_maps.erase(map_base); } container.push_back(&map_base); - map_base.graph = this; + map_base.graph = graph; map_base.graph_index = container.size()-1; } - void erase(NodeMapBase& map_base) { - if (map_base.graph != this) return; + void erase(MapBase& map_base) { container.back()->graph_index = map_base.graph_index; container[map_base.graph_index] = container.back(); container.pop_back(); map_base.graph = 0; } + void add(Node& node) { typename Container::iterator it; @@ -49,7 +60,6 @@ } } - friend class NodeMapBase; }; #endif diff -r 5c12f3515452 -r 33fe0ee01dc5 src/work/deba/slowgraph.h --- a/src/work/deba/slowgraph.h Thu Apr 22 16:07:17 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -#ifndef SLOWGRAPH_H -#define SLOWGRAPH_H - -class SlowGraphBase { -private: - typedef vector EdgeVector; - typedef vector NodeVector; - - NodeVector in_nodes, out_nodes; - -public: - typedef Edge -}; - -typedef MappedGraph SlowGraph; - -#endif \ No newline at end of file diff -r 5c12f3515452 -r 33fe0ee01dc5 src/work/deba/test_graph.h --- a/src/work/deba/test_graph.h Thu Apr 22 16:07:17 2004 +0000 +++ b/src/work/deba/test_graph.h Thu Apr 22 16:36:57 2004 +0000 @@ -5,13 +5,13 @@ #include #include -#include +#include "invalid.h" -#include "vector_map.h" #include "edge_map_registry.h" #include "node_map_registry.h" #include "edge_map_base.h" #include "node_map_base.h" +#include "vector_map.h" namespace hugo { @@ -40,15 +40,24 @@ // template friend class NodeMap; // template friend class EdgeMap; - NodeMapRegistry node_maps; + private: + + NodeMapRegistry node_maps(*this); + EdgeMapRegistry edge_maps(*this); + + public: + template - class NodeMap : public VectorMap {}; + class NodeMap : public VectorMap { + public: + NodeMap(ListGraph& g) : VectorMap(g) {} + }; EdgeMapRegistry edge_maps; template - class EdgeMap : public VectorMap {}; + class EdgeMap : public VectorMap {}; int node_id; @@ -310,7 +319,7 @@ } void erase(Node i) { - node_map.erase(i); + node_maps.erase(i); while (first(i).valid()) erase(first(i)); while (first(i).valid()) erase(first(i)); _delete_node(i.node); diff -r 5c12f3515452 -r 33fe0ee01dc5 src/work/deba/vector_map.h --- a/src/work/deba/vector_map.h Thu Apr 22 16:07:17 2004 +0000 +++ b/src/work/deba/vector_map.h Thu Apr 22 16:36:57 2004 +0000 @@ -34,7 +34,9 @@ } void add(const K& key) { - container.resize(key->id); + if (key->id() >= container.size()) { + container.resize(key->id() + 1); + } } void erase(const K& key) {} @@ -43,6 +45,6 @@ typedef std::vector Container; Container container; -} +}; #endif