alpar@906
|
1 |
/* -*- C++ -*-
|
ladanyi@1435
|
2 |
* lemon/default_map.h - Part of LEMON, a generic C++ optimization library
|
alpar@906
|
3 |
*
|
alpar@1164
|
4 |
* Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@1359
|
5 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@906
|
6 |
*
|
alpar@906
|
7 |
* Permission to use, modify and distribute this software is granted
|
alpar@906
|
8 |
* provided that this copyright notice appears in all copies. For
|
alpar@906
|
9 |
* precise terms see the accompanying LICENSE file.
|
alpar@906
|
10 |
*
|
alpar@906
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@906
|
12 |
* express or implied, and with no claim as to its suitability for any
|
alpar@906
|
13 |
* purpose.
|
alpar@906
|
14 |
*
|
alpar@906
|
15 |
*/
|
alpar@906
|
16 |
|
alpar@921
|
17 |
#ifndef LEMON_DEFAULT_MAP_H
|
alpar@921
|
18 |
#define LEMON_DEFAULT_MAP_H
|
deba@822
|
19 |
|
deba@822
|
20 |
|
deba@1307
|
21 |
#include <lemon/bits/array_map.h>
|
deba@1307
|
22 |
#include <lemon/bits/vector_map.h>
|
deba@822
|
23 |
|
deba@822
|
24 |
///\ingroup graphmaps
|
deba@822
|
25 |
///\file
|
klao@946
|
26 |
///\brief Graph maps that construct and destruct
|
deba@822
|
27 |
///their elements dynamically.
|
deba@822
|
28 |
|
alpar@921
|
29 |
namespace lemon {
|
deba@822
|
30 |
|
deba@822
|
31 |
/// \addtogroup graphmaps
|
deba@822
|
32 |
/// @{
|
deba@822
|
33 |
|
deba@822
|
34 |
/** The ArrayMap template class is graph map structure what
|
deba@822
|
35 |
* automatically updates the map when a key is added to or erased from
|
alpar@987
|
36 |
* the map. This map uses the VectorMap if the Value is a primitive
|
deba@822
|
37 |
* type and the ArrayMap for the other cases.
|
deba@822
|
38 |
*
|
deba@822
|
39 |
* The template parameter is the MapRegistry that the maps
|
alpar@987
|
40 |
* will belong to and the Value.
|
deba@822
|
41 |
*/
|
deba@822
|
42 |
|
deba@822
|
43 |
|
deba@822
|
44 |
|
deba@1267
|
45 |
template <typename _Graph, typename _Item, typename _Value>
|
klao@946
|
46 |
struct DefaultMapSelector {
|
deba@1267
|
47 |
typedef ArrayMap<_Graph, _Item, _Value> Map;
|
klao@946
|
48 |
};
|
deba@822
|
49 |
|
klao@946
|
50 |
// bool
|
deba@1267
|
51 |
template <typename _Graph, typename _Item>
|
deba@1267
|
52 |
struct DefaultMapSelector<_Graph, _Item, bool> {
|
deba@980
|
53 |
typedef VectorMap<_Graph, _Item, bool> Map;
|
klao@946
|
54 |
};
|
deba@822
|
55 |
|
klao@946
|
56 |
// char
|
deba@1267
|
57 |
template <typename _Graph, typename _Item>
|
deba@1267
|
58 |
struct DefaultMapSelector<_Graph, _Item, char> {
|
deba@980
|
59 |
typedef VectorMap<_Graph, _Item, char> Map;
|
klao@946
|
60 |
};
|
deba@822
|
61 |
|
deba@1267
|
62 |
template <typename _Graph, typename _Item>
|
deba@1267
|
63 |
struct DefaultMapSelector<_Graph, _Item, signed char> {
|
deba@980
|
64 |
typedef VectorMap<_Graph, _Item, signed char> Map;
|
klao@946
|
65 |
};
|
deba@822
|
66 |
|
deba@1267
|
67 |
template <typename _Graph, typename _Item>
|
deba@1267
|
68 |
struct DefaultMapSelector<_Graph, _Item, unsigned char> {
|
deba@980
|
69 |
typedef VectorMap<_Graph, _Item, unsigned char> Map;
|
klao@946
|
70 |
};
|
deba@822
|
71 |
|
deba@822
|
72 |
|
klao@946
|
73 |
// int
|
deba@1267
|
74 |
template <typename _Graph, typename _Item>
|
deba@1267
|
75 |
struct DefaultMapSelector<_Graph, _Item, signed int> {
|
deba@980
|
76 |
typedef VectorMap<_Graph, _Item, signed int> Map;
|
klao@946
|
77 |
};
|
deba@822
|
78 |
|
deba@1267
|
79 |
template <typename _Graph, typename _Item>
|
deba@1267
|
80 |
struct DefaultMapSelector<_Graph, _Item, unsigned int> {
|
deba@980
|
81 |
typedef VectorMap<_Graph, _Item, unsigned int> Map;
|
klao@946
|
82 |
};
|
deba@822
|
83 |
|
deba@822
|
84 |
|
klao@946
|
85 |
// short
|
deba@1267
|
86 |
template <typename _Graph, typename _Item>
|
deba@1267
|
87 |
struct DefaultMapSelector<_Graph, _Item, signed short> {
|
deba@980
|
88 |
typedef VectorMap<_Graph, _Item, signed short> Map;
|
klao@946
|
89 |
};
|
deba@822
|
90 |
|
deba@1267
|
91 |
template <typename _Graph, typename _Item>
|
deba@1267
|
92 |
struct DefaultMapSelector<_Graph, _Item, unsigned short> {
|
deba@980
|
93 |
typedef VectorMap<_Graph, _Item, unsigned short> Map;
|
klao@946
|
94 |
};
|
klao@946
|
95 |
|
klao@946
|
96 |
|
klao@946
|
97 |
// long
|
deba@1267
|
98 |
template <typename _Graph, typename _Item>
|
deba@1267
|
99 |
struct DefaultMapSelector<_Graph, _Item, signed long> {
|
deba@980
|
100 |
typedef VectorMap<_Graph, _Item, signed long> Map;
|
klao@946
|
101 |
};
|
klao@946
|
102 |
|
deba@1267
|
103 |
template <typename _Graph, typename _Item>
|
deba@1267
|
104 |
struct DefaultMapSelector<_Graph, _Item, unsigned long> {
|
deba@980
|
105 |
typedef VectorMap<_Graph, _Item, unsigned long> Map;
|
klao@946
|
106 |
};
|
klao@946
|
107 |
|
klao@946
|
108 |
// \todo handling long long type
|
klao@946
|
109 |
|
klao@946
|
110 |
|
klao@946
|
111 |
// float
|
deba@1267
|
112 |
template <typename _Graph, typename _Item>
|
deba@1267
|
113 |
struct DefaultMapSelector<_Graph, _Item, float> {
|
deba@980
|
114 |
typedef VectorMap<_Graph, _Item, float> Map;
|
klao@946
|
115 |
};
|
klao@946
|
116 |
|
klao@946
|
117 |
|
klao@946
|
118 |
// double
|
deba@1267
|
119 |
template <typename _Graph, typename _Item>
|
deba@1267
|
120 |
struct DefaultMapSelector<_Graph, _Item, double> {
|
deba@980
|
121 |
typedef VectorMap<_Graph, _Item, double> Map;
|
klao@946
|
122 |
};
|
klao@946
|
123 |
|
klao@946
|
124 |
|
klao@946
|
125 |
// long double
|
deba@1267
|
126 |
template <typename _Graph, typename _Item>
|
deba@1267
|
127 |
struct DefaultMapSelector<_Graph, _Item, long double> {
|
deba@980
|
128 |
typedef VectorMap<_Graph, _Item, long double> Map;
|
klao@946
|
129 |
};
|
klao@946
|
130 |
|
klao@946
|
131 |
|
klao@946
|
132 |
// pointer
|
deba@1267
|
133 |
template <typename _Graph, typename _Item, typename _Ptr>
|
deba@1267
|
134 |
struct DefaultMapSelector<_Graph, _Item, _Ptr*> {
|
deba@980
|
135 |
typedef VectorMap<_Graph, _Item, _Ptr*> Map;
|
klao@946
|
136 |
};
|
klao@946
|
137 |
|
klao@946
|
138 |
|
klao@946
|
139 |
|
deba@1267
|
140 |
template <
|
deba@1267
|
141 |
typename _Graph,
|
deba@1267
|
142 |
typename _Item,
|
deba@1267
|
143 |
typename _Value>
|
deba@1267
|
144 |
class DefaultMap
|
deba@1267
|
145 |
: public DefaultMapSelector<_Graph, _Item, _Value>::Map {
|
klao@946
|
146 |
public:
|
deba@1267
|
147 |
typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent;
|
deba@1267
|
148 |
typedef DefaultMap<_Graph, _Item, _Value> Map;
|
klao@946
|
149 |
|
klao@946
|
150 |
typedef typename Parent::Graph Graph;
|
alpar@987
|
151 |
typedef typename Parent::Value Value;
|
klao@946
|
152 |
|
deba@980
|
153 |
DefaultMap(const Graph& _g) : Parent(_g) {}
|
alpar@987
|
154 |
DefaultMap(const Graph& _g, const Value& _v) : Parent(_g, _v) {}
|
klao@946
|
155 |
};
|
klao@946
|
156 |
|
klao@946
|
157 |
|
klao@946
|
158 |
|
klao@946
|
159 |
template <typename _Base>
|
klao@946
|
160 |
class DefaultMappableGraphExtender : public _Base {
|
klao@946
|
161 |
public:
|
klao@946
|
162 |
|
klao@946
|
163 |
typedef DefaultMappableGraphExtender<_Base> Graph;
|
klao@946
|
164 |
typedef _Base Parent;
|
klao@946
|
165 |
|
klao@946
|
166 |
typedef typename Parent::Node Node;
|
klao@946
|
167 |
typedef typename Parent::NodeIt NodeIt;
|
klao@946
|
168 |
|
klao@946
|
169 |
typedef typename Parent::Edge Edge;
|
klao@946
|
170 |
typedef typename Parent::EdgeIt EdgeIt;
|
klao@946
|
171 |
|
klao@946
|
172 |
|
klao@946
|
173 |
template <typename _Value>
|
deba@1267
|
174 |
class NodeMap
|
deba@1267
|
175 |
: public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
|
klao@946
|
176 |
public:
|
klao@1022
|
177 |
typedef DefaultMappableGraphExtender Graph;
|
deba@1267
|
178 |
typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
|
klao@946
|
179 |
|
deba@980
|
180 |
NodeMap(const Graph& _g)
|
deba@980
|
181 |
: Parent(_g) {}
|
klao@1022
|
182 |
NodeMap(const Graph& _g, const _Value& _v)
|
deba@980
|
183 |
: Parent(_g, _v) {}
|
klao@946
|
184 |
};
|
klao@946
|
185 |
|
klao@946
|
186 |
template <typename _Value>
|
deba@1267
|
187 |
class EdgeMap
|
deba@1267
|
188 |
: public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
|
klao@946
|
189 |
public:
|
klao@1022
|
190 |
typedef DefaultMappableGraphExtender Graph;
|
deba@1267
|
191 |
typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
|
klao@946
|
192 |
|
deba@980
|
193 |
EdgeMap(const Graph& _g)
|
deba@980
|
194 |
: Parent(_g) {}
|
klao@1022
|
195 |
EdgeMap(const Graph& _g, const _Value& _v)
|
deba@980
|
196 |
: Parent(_g, _v) {}
|
klao@946
|
197 |
};
|
klao@946
|
198 |
|
klao@946
|
199 |
};
|
klao@946
|
200 |
|
klao@1022
|
201 |
template <typename _Base>
|
klao@1022
|
202 |
class MappableUndirGraphExtender :
|
klao@1022
|
203 |
public DefaultMappableGraphExtender<_Base> {
|
klao@1022
|
204 |
public:
|
klao@1022
|
205 |
|
klao@1022
|
206 |
typedef MappableUndirGraphExtender Graph;
|
klao@1022
|
207 |
typedef DefaultMappableGraphExtender<_Base> Parent;
|
klao@1022
|
208 |
|
klao@1022
|
209 |
typedef typename Parent::UndirEdge UndirEdge;
|
klao@1022
|
210 |
|
klao@1022
|
211 |
template <typename _Value>
|
deba@1267
|
212 |
class UndirEdgeMap
|
deba@1267
|
213 |
: public IterableMapExtender<DefaultMap<Graph, UndirEdge, _Value> > {
|
klao@1022
|
214 |
public:
|
klao@1022
|
215 |
typedef MappableUndirGraphExtender Graph;
|
deba@1267
|
216 |
typedef IterableMapExtender<
|
deba@1267
|
217 |
DefaultMap<Graph, UndirEdge, _Value> > Parent;
|
klao@1022
|
218 |
|
klao@1022
|
219 |
UndirEdgeMap(const Graph& _g)
|
klao@1022
|
220 |
: Parent(_g) {}
|
klao@1022
|
221 |
UndirEdgeMap(const Graph& _g, const _Value& _v)
|
klao@1022
|
222 |
: Parent(_g, _v) {}
|
klao@1022
|
223 |
};
|
klao@1022
|
224 |
|
klao@1022
|
225 |
|
klao@1022
|
226 |
};
|
deba@822
|
227 |
|
deba@822
|
228 |
}
|
deba@822
|
229 |
|
deba@822
|
230 |
#endif
|