(none)
authordeba
Mon, 29 Mar 2004 20:34:24 +0000
changeset 261796101caedb7
parent 260 fb27d1c7036e
child 262 60de0f16a4a1
(none)
src/work/deba/mapbase.h
src/work/deba/mappedgraph.h
src/work/deba/slowgraph.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/work/deba/mapbase.h	Mon Mar 29 20:34:24 2004 +0000
     1.3 @@ -0,0 +1,31 @@
     1.4 +#ifndef MAPBASE_H
     1.5 +#define MAPBASE_H
     1.6 +
     1.7 +template <class GB, class K>
     1.8 +class MapBase {
     1.9 +public:
    1.10 +	typedef GB GraphBase;
    1.11 +	typedef MappedGraph<GraphBase> Graph;
    1.12 +
    1.13 +	typedef K KeyType;
    1.14 +	
    1.15 +
    1.16 +	MapBase() : graph(0) {}
    1.17 +	MapBase(Graph& g) : graph(&g) {graph.add(*this);}
    1.18 +
    1.19 +	virtual ~MapBase() {graph.erase(*this);}	
    1.20 +
    1.21 +protected:
    1.22 +	
    1.23 +	Graph* graph;
    1.24 +
    1.25 +	int graph_index;
    1.26 +	
    1.27 +	
    1.28 +	virtual void add(const KeyType&) = 0;
    1.29 +	virtual void erase(const KeyType&) = 0;
    1.30 +
    1.31 +	friend class Graph;
    1.32 +};
    1.33 +
    1.34 +#endif
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/work/deba/mappedgraph.h	Mon Mar 29 20:34:24 2004 +0000
     2.3 @@ -0,0 +1,88 @@
     2.4 +#ifndef MAPPEDGRAPH_H
     2.5 +#define MAPPEDGRAPH_H
     2.6 +
     2.7 +#include <vector>
     2.8 +
     2.9 +template <typename GB, typename K>
    2.10 +class MapBase;
    2.11 +
    2.12 +template <typename GB>
    2.13 +class MappedGraph : public GB {
    2.14 +public:
    2.15 +	typedef GB GraphBase;
    2.16 +	
    2.17 +	typedef MapBase<GB, typename GB::Edge> EdgeMapBase;
    2.18 +	typedef MapBase<GB, typename GB::Node> NodeMapBase;
    2.19 +
    2.20 +protected:
    2.21 +	typedef std::vector<EdgeMapBase*> EdgeMaps; 
    2.22 +	typedef std::vector<NodeMapBase*> NodeMaps;
    2.23 +	
    2.24 +	EdgeMaps edge_maps;
    2.25 +	NodeMaps node_maps;
    2.26 +	
    2.27 +	void add(EdgeMapBase& map_base) {
    2.28 +		if (map_base.graph) {
    2.29 +			map_base.graph->erase(map_base);
    2.30 +		}
    2.31 +		edge_maps.push_back(&map_base);
    2.32 +		map_base.graph_index = map_base.size()-1;
    2.33 +	} 
    2.34 +	
    2.35 +	void erase(EdgeMapBase& map_base) {
    2.36 +		if (map_base.graph != this) return;
    2.37 +		edge_maps.back()->graph_index = map_base.graph_index; 
    2.38 +		edge_maps[map_base.graph_index] = edge_maps.back();
    2.39 +		edge_maps.pop_back();
    2.40 +		map_base.graph = 0;
    2.41 +	}
    2.42 +	
    2.43 +	void addEdge(typename GB::Edge& edge) {
    2.44 +		typename EdgeMaps::iterator it;
    2.45 +		for (it = edge_maps.begin(); it != edge_maps.end(); ++it) {
    2.46 +			(*it)->add(edge);
    2.47 +		}
    2.48 +	}
    2.49 +	
    2.50 +	void eraseEdge(typename GB::Edge& edge) {
    2.51 +		typename EdgeMaps::iterator it;
    2.52 +		for (it = edge_maps.begin(); it != edge_maps.end(); ++it) {
    2.53 +			(*it)->erase(edge);
    2.54 +		}
    2.55 +	}
    2.56 +
    2.57 +	void add(NodeMapBase& map_base) {
    2.58 +		if (map_base.graph) {
    2.59 +			map_base.graph->erase(map_base);
    2.60 +		}
    2.61 +		node_maps.push_back(&map_base);
    2.62 +		map_base.graph_index = node_maps.size()-1;
    2.63 +	} 
    2.64 +	
    2.65 +	void erase(NodeMapBase& map_base) {
    2.66 +		if (map_base.graph != this) return;
    2.67 +		node_maps.back()->graph_index = map_base.graph_index; 
    2.68 +		node_maps[map_base.graph_index] = node_maps.back();
    2.69 +		node_maps.pop_back();
    2.70 +		map_base.graph = 0;
    2.71 +	}
    2.72 +
    2.73 +	void addNode(typename GB::Node& node) {
    2.74 +		typename NodeMaps::iterator it;
    2.75 +		for (it = node_maps.begin(); it != node_maps.end(); ++it) {
    2.76 +			(*it)->add(node);
    2.77 +		}
    2.78 +	}
    2.79 +	
    2.80 +	void eraseNode(typename GB::Node& node) {
    2.81 +		typename NodeMaps::iterator it;
    2.82 +		for (it = node_maps.begin(); it != node_maps.end(); ++it) {
    2.83 +			(*it)->erase(node);
    2.84 +		}
    2.85 +	}
    2.86 +	
    2.87 +	friend class EdgeMapBase;
    2.88 +	friend class NodeMapBase;
    2.89 +};
    2.90 +
    2.91 +#endif
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/work/deba/slowgraph.h	Mon Mar 29 20:34:24 2004 +0000
     3.3 @@ -0,0 +1,17 @@
     3.4 +#ifndef SLOWGRAPH_H
     3.5 +#define SLOWGRAPH_H
     3.6 +
     3.7 +class SlowGraphBase {
     3.8 +private:
     3.9 +	typedef vector<int> EdgeVector;
    3.10 +  typedef vector<EdgeVector> NodeVector;
    3.11 +	
    3.12 +  NodeVector in_nodes, out_nodes;
    3.13 +
    3.14 +public:
    3.15 +	typedef Edge
    3.16 +};
    3.17 +
    3.18 +typedef MappedGraph<SlowGraphBase> SlowGraph;
    3.19 +
    3.20 +#endif
    3.21 \ No newline at end of file