[Lemon-commits] [lemon_svn] deba: r507 - hugo/trunk/src/work/deba
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:39:50 CET 2006
Author: deba
Date: Thu Apr 22 18:36:57 2004
New Revision: 507
Removed:
hugo/trunk/src/work/deba/edge_map_register.h
hugo/trunk/src/work/deba/mapbase.h
hugo/trunk/src/work/deba/mappedgraph.h
hugo/trunk/src/work/deba/slowgraph.h
Modified:
hugo/trunk/src/work/deba/edge_map_base.h
hugo/trunk/src/work/deba/edge_map_registry.h
hugo/trunk/src/work/deba/node_map_base.h
hugo/trunk/src/work/deba/node_map_registry.h
hugo/trunk/src/work/deba/test_graph.h
hugo/trunk/src/work/deba/vector_map.h
Log:
Modified: hugo/trunk/src/work/deba/edge_map_base.h
==============================================================================
--- hugo/trunk/src/work/deba/edge_map_base.h (original)
+++ hugo/trunk/src/work/deba/edge_map_base.h Thu Apr 22 18:36:57 2004
@@ -11,8 +11,12 @@
template <typename G, typename K>
class EdgeMapBase {
+
+#include "edge_map_registry.h"
+
public:
typedef G Graph;
+ friend class EdgeMapRegistry<G, K>;
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
Modified: hugo/trunk/src/work/deba/edge_map_registry.h
==============================================================================
--- hugo/trunk/src/work/deba/edge_map_registry.h (original)
+++ hugo/trunk/src/work/deba/edge_map_registry.h Thu Apr 22 18:36:57 2004
@@ -3,37 +3,48 @@
#include <vector>
+template <typename G, typename K>
+class EdgeMapRegistry;
+
#include "edge_map_base.h"
-template <typename G, typename E>
+template <typename G, typename K>
class EdgeMapRegistry {
public:
typedef G Graph;
- typedef E Edge
+ typedef K Edge;
typedef EdgeMapBase<Graph, Edge> MapBase;
+ friend class MapBase;
protected:
- typedef std::vector<EdgeMapBase*> Container;
- Container container;
+ Graph* graph;
+
+ typedef std::vector<MapBase*> 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
Modified: hugo/trunk/src/work/deba/node_map_base.h
==============================================================================
--- hugo/trunk/src/work/deba/node_map_base.h (original)
+++ hugo/trunk/src/work/deba/node_map_base.h Thu Apr 22 18:36:57 2004
@@ -11,8 +11,12 @@
template <typename G, typename K>
class NodeMapBase {
+
+#include "node_map_registry.h"
+
public:
typedef G Graph;
+ friend class NodeMapRegistry<G, K>;
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
Modified: hugo/trunk/src/work/deba/node_map_registry.h
==============================================================================
--- hugo/trunk/src/work/deba/node_map_registry.h (original)
+++ hugo/trunk/src/work/deba/node_map_registry.h Thu Apr 22 18:36:57 2004
@@ -3,37 +3,48 @@
#include <vector>
+template <typename G, typename K>
+class NodeMapRegistry;
+
#include "node_map_base.h"
-template <typename G, typename E>
+template <typename G, typename K>
class NodeMapRegistry {
public:
typedef G Graph;
- typedef E Node
+ typedef K Node;
- typedef NodeMapBase<Graph, Node> NodeMapBase;
+ typedef NodeMapBase<Graph, Node> MapBase;
+ friend class MapBase;
protected:
- typedef std::vector<NodeMapBase*> Container;
- Container container;
+ Graph* graph;
+
+ typedef std::vector<MapBase*> Container;
- void add(NodeMapBase& map_base) {
+ Container container;
+
+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
Modified: hugo/trunk/src/work/deba/test_graph.h
==============================================================================
--- hugo/trunk/src/work/deba/test_graph.h (original)
+++ hugo/trunk/src/work/deba/test_graph.h Thu Apr 22 18:36:57 2004
@@ -5,13 +5,13 @@
#include <iostream>
#include <vector>
-#include <invalid.h>
+#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 <typename T> friend class NodeMap;
// template <typename T> friend class EdgeMap;
- NodeMapRegistry<ListGraph, Node> node_maps;
+ private:
+
+ NodeMapRegistry<ListGraph, Node> node_maps(*this);
+ EdgeMapRegistry<ListGraph, Edge> edge_maps(*this);
+
+ public:
+
template <typename T>
- class NodeMap : public VectorMap<ListGraph, Edge, T, EdgeMapBase> {};
+ class NodeMap : public VectorMap<ListGraph, Node, T, NodeMapBase> {
+ public:
+ NodeMap(ListGraph& g) : VectorMap<ListGraph, Node, T, NodeMapBase>(g) {}
+ };
EdgeMapRegistry<ListGraph, Edge> edge_maps;
template <typename T>
- class EdgeMap : public VectorMap<Graph, Node, T, NodeMapBase> {};
+ class EdgeMap : public VectorMap<ListGraph, Edge, T, EdgeMapBase> {};
int node_id;
@@ -310,7 +319,7 @@
}
void erase(Node i) {
- node_map.erase(i);
+ node_maps.erase(i);
while (first<OutEdgeIt>(i).valid()) erase(first<OutEdgeIt>(i));
while (first<InEdgeIt>(i).valid()) erase(first<InEdgeIt>(i));
_delete_node(i.node);
Modified: hugo/trunk/src/work/deba/vector_map.h
==============================================================================
--- hugo/trunk/src/work/deba/vector_map.h (original)
+++ hugo/trunk/src/work/deba/vector_map.h Thu Apr 22 18:36:57 2004
@@ -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<ValueType> Container;
Container container;
-}
+};
#endif
More information about the Lemon-commits
mailing list