COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/deba/mappedgraph.h @ 376:5c12f3515452

Last change on this file since 376:5c12f3515452 was 261:796101caedb7, checked in by Balazs Dezso, 20 years ago
File size: 2.0 KB
Line 
1#ifndef MAPPEDGRAPH_H
2#define MAPPEDGRAPH_H
3
4#include <vector>
5
6template <typename GB, typename K>
7class MapBase;
8
9template <typename GB>
10class MappedGraph : public GB {
11public:
12        typedef GB GraphBase;
13       
14        typedef MapBase<GB, typename GB::Edge> EdgeMapBase;
15        typedef MapBase<GB, typename GB::Node> NodeMapBase;
16
17protected:
18        typedef std::vector<EdgeMapBase*> EdgeMaps;
19        typedef std::vector<NodeMapBase*> NodeMaps;
20       
21        EdgeMaps edge_maps;
22        NodeMaps node_maps;
23       
24        void add(EdgeMapBase& map_base) {
25                if (map_base.graph) {
26                        map_base.graph->erase(map_base);
27                }
28                edge_maps.push_back(&map_base);
29                map_base.graph_index = map_base.size()-1;
30        }
31       
32        void erase(EdgeMapBase& map_base) {
33                if (map_base.graph != this) return;
34                edge_maps.back()->graph_index = map_base.graph_index;
35                edge_maps[map_base.graph_index] = edge_maps.back();
36                edge_maps.pop_back();
37                map_base.graph = 0;
38        }
39       
40        void addEdge(typename GB::Edge& edge) {
41                typename EdgeMaps::iterator it;
42                for (it = edge_maps.begin(); it != edge_maps.end(); ++it) {
43                        (*it)->add(edge);
44                }
45        }
46       
47        void eraseEdge(typename GB::Edge& edge) {
48                typename EdgeMaps::iterator it;
49                for (it = edge_maps.begin(); it != edge_maps.end(); ++it) {
50                        (*it)->erase(edge);
51                }
52        }
53
54        void add(NodeMapBase& map_base) {
55                if (map_base.graph) {
56                        map_base.graph->erase(map_base);
57                }
58                node_maps.push_back(&map_base);
59                map_base.graph_index = node_maps.size()-1;
60        }
61       
62        void erase(NodeMapBase& map_base) {
63                if (map_base.graph != this) return;
64                node_maps.back()->graph_index = map_base.graph_index;
65                node_maps[map_base.graph_index] = node_maps.back();
66                node_maps.pop_back();
67                map_base.graph = 0;
68        }
69
70        void addNode(typename GB::Node& node) {
71                typename NodeMaps::iterator it;
72                for (it = node_maps.begin(); it != node_maps.end(); ++it) {
73                        (*it)->add(node);
74                }
75        }
76       
77        void eraseNode(typename GB::Node& node) {
78                typename NodeMaps::iterator it;
79                for (it = node_maps.begin(); it != node_maps.end(); ++it) {
80                        (*it)->erase(node);
81                }
82        }
83       
84        friend class EdgeMapBase;
85        friend class NodeMapBase;
86};
87
88#endif
Note: See TracBrowser for help on using the repository browser.