gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Add missing tags and indicators
0 4 0
default
4 files changed with 31 insertions and 1 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -197,61 +197,87 @@
197 197

	
198 198
    typedef typename MatrixMap::ConstReference ConstReturnValue;
199 199
    typedef typename MatrixMap::Reference ReturnValue;
200 200

	
201 201
    typedef typename MatrixMap::ConstReference ConstReference;
202 202
    typedef typename MatrixMap::Reference Reference;
203 203
 };
204 204

	
205 205
  // Indicators for the tags
206 206

	
207 207
  template <typename Graph, typename Enable = void>
208 208
  struct NodeNumTagIndicator {
209 209
    static const bool value = false;
210 210
  };
211 211

	
212 212
  template <typename Graph>
213 213
  struct NodeNumTagIndicator<
214 214
    Graph,
215 215
    typename enable_if<typename Graph::NodeNumTag, void>::type
216 216
  > {
217 217
    static const bool value = true;
218 218
  };
219 219

	
220 220
  template <typename Graph, typename Enable = void>
221
  struct ArcNumTagIndicator {
222
    static const bool value = false;
223
  };
224

	
225
  template <typename Graph>
226
  struct ArcNumTagIndicator<
227
    Graph,
228
    typename enable_if<typename Graph::ArcNumTag, void>::type
229
  > {
230
    static const bool value = true;
231
  };
232

	
233
  template <typename Graph, typename Enable = void>
221 234
  struct EdgeNumTagIndicator {
222 235
    static const bool value = false;
223 236
  };
224 237

	
225 238
  template <typename Graph>
226 239
  struct EdgeNumTagIndicator<
227 240
    Graph,
228 241
    typename enable_if<typename Graph::EdgeNumTag, void>::type
229 242
  > {
230 243
    static const bool value = true;
231 244
  };
232 245

	
233 246
  template <typename Graph, typename Enable = void>
247
  struct FindArcTagIndicator {
248
    static const bool value = false;
249
  };
250

	
251
  template <typename Graph>
252
  struct FindArcTagIndicator<
253
    Graph,
254
    typename enable_if<typename Graph::FindArcTag, void>::type
255
  > {
256
    static const bool value = true;
257
  };
258

	
259
  template <typename Graph, typename Enable = void>
234 260
  struct FindEdgeTagIndicator {
235 261
    static const bool value = false;
236 262
  };
237 263

	
238 264
  template <typename Graph>
239 265
  struct FindEdgeTagIndicator<
240 266
    Graph,
241 267
    typename enable_if<typename Graph::FindEdgeTag, void>::type
242 268
  > {
243 269
    static const bool value = true;
244 270
  };
245 271

	
246 272
  template <typename Graph, typename Enable = void>
247 273
  struct UndirectedTagIndicator {
248 274
    static const bool value = false;
249 275
  };
250 276

	
251 277
  template <typename Graph>
252 278
  struct UndirectedTagIndicator<
253 279
    Graph,
254 280
    typename enable_if<typename Graph::UndirectedTag, void>::type
255 281
  > {
256 282
    static const bool value = true;
257 283
  };
Ignore white space 48 line context
... ...
@@ -285,85 +285,87 @@
285 285
    Node operator()(int ix) const { return Node(ix); }
286 286
    int index(const Node& node) const { return node._id; }
287 287

	
288 288
    Edge edge(const Node& u, const Node& v) const {
289 289
      if (u._id < v._id) {
290 290
        return Edge(_eid(u._id, v._id));
291 291
      } else if (u._id != v._id) {
292 292
        return Edge(_eid(v._id, u._id));
293 293
      } else {
294 294
        return INVALID;
295 295
      }
296 296
    }
297 297

	
298 298
    Arc arc(const Node& s, const Node& t) const {
299 299
      if (s._id < t._id) {
300 300
        return Arc((_eid(s._id, t._id) << 1) | 1);
301 301
      } else if (s._id != t._id) {
302 302
        return Arc(_eid(t._id, s._id) << 1);
303 303
      } else {
304 304
        return INVALID;
305 305
      }
306 306
    }
307 307

	
308 308
    typedef True NodeNumTag;
309
    typedef True ArcNumTag;
309 310
    typedef True EdgeNumTag;
310 311

	
311 312
    int nodeNum() const { return _node_num; }
312 313
    int arcNum() const { return 2 * _edge_num; }
313 314
    int edgeNum() const { return _edge_num; }
314 315

	
315 316
    static int id(Node node) { return node._id; }
316 317
    static int id(Arc arc) { return arc._id; }
317 318
    static int id(Edge edge) { return edge._id; }
318 319

	
319 320
    int maxNodeId() const { return _node_num-1; }
320 321
    int maxArcId() const { return 2 * _edge_num-1; }
321 322
    int maxEdgeId() const { return _edge_num-1; }
322 323

	
323 324
    static Node nodeFromId(int id) { return Node(id);}
324 325
    static Arc arcFromId(int id) { return Arc(id);}
325 326
    static Edge edgeFromId(int id) { return Edge(id);}
326 327

	
327 328
    Node u(Edge edge) const {
328 329
      return Node(_uid(edge._id));
329 330
    }
330 331

	
331 332
    Node v(Edge edge) const {
332 333
      return Node(_vid(edge._id));
333 334
    }
334 335

	
335 336
    Node source(Arc arc) const {
336 337
      return Node((arc._id & 1) == 1 ?
337 338
                  _uid(arc._id >> 1) : _vid(arc._id >> 1));
338 339
    }
339 340

	
340 341
    Node target(Arc arc) const {
341 342
      return Node((arc._id & 1) == 1 ?
342 343
                  _vid(arc._id >> 1) : _uid(arc._id >> 1));
343 344
    }
344 345

	
345 346
    typedef True FindEdgeTag;
347
    typedef True FindArcTag;
346 348

	
347 349
    Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
348 350
      return prev != INVALID ? INVALID : edge(u, v);
349 351
    }
350 352

	
351 353
    Arc findArc(Node s, Node t, Arc prev = INVALID) const {
352 354
      return prev != INVALID ? INVALID : arc(s, t);
353 355
    }
354 356

	
355 357
    class Node {
356 358
      friend class FullGraphBase;
357 359

	
358 360
    protected:
359 361
      int _id;
360 362
      Node(int id) : _id(id) {}
361 363
    public:
362 364
      Node() {}
363 365
      Node (Invalid) { _id = -1; }
364 366
      bool operator==(const Node node) const {return _id == node._id;}
365 367
      bool operator!=(const Node node) const {return _id != node._id;}
366 368
      bool operator<(const Node node) const {return _id < node._id;}
367 369
    };
368 370

	
369 371
    class Edge {
Ignore white space 6 line context
... ...
@@ -61,93 +61,95 @@
61 61
      return Node(i + j * _width);
62 62
    }
63 63

	
64 64
    int col(Node n) const {
65 65
      return n._id % _width;
66 66
    }
67 67

	
68 68
    int row(Node n) const {
69 69
      return n._id / _width;
70 70
    }
71 71

	
72 72
    dim2::Point<int> pos(Node n) const {
73 73
      return dim2::Point<int>(col(n), row(n));
74 74
    }
75 75

	
76 76
    int width() const {
77 77
      return _width;
78 78
    }
79 79

	
80 80
    int height() const {
81 81
      return _height;
82 82
    }
83 83

	
84 84
    typedef True NodeNumTag;
85
    typedef True EdgeNumTag;
85 86
    typedef True ArcNumTag;
86 87

	
87 88
    int nodeNum() const { return _node_num; }
88 89
    int edgeNum() const { return _edge_num; }
89 90
    int arcNum() const { return 2 * _edge_num; }
90 91

	
91 92
    Node u(Edge edge) const {
92 93
      if (edge._id < _edge_limit) {
93 94
        return edge._id;
94 95
      } else {
95 96
        return (edge._id - _edge_limit) % (_width - 1) +
96 97
          (edge._id - _edge_limit) / (_width - 1) * _width;
97 98
      }
98 99
    }
99 100

	
100 101
    Node v(Edge edge) const {
101 102
      if (edge._id < _edge_limit) {
102 103
        return edge._id + _width;
103 104
      } else {
104 105
        return (edge._id - _edge_limit) % (_width - 1) +
105 106
          (edge._id - _edge_limit) / (_width - 1) * _width + 1;
106 107
      }
107 108
    }
108 109

	
109 110
    Node source(Arc arc) const {
110 111
      return (arc._id & 1) == 1 ? u(arc) : v(arc);
111 112
    }
112 113

	
113 114
    Node target(Arc arc) const {
114 115
      return (arc._id & 1) == 1 ? v(arc) : u(arc);
115 116
    }
116 117

	
117 118
    static int id(Node node) { return node._id; }
118 119
    static int id(Edge edge) { return edge._id; }
119 120
    static int id(Arc arc) { return arc._id; }
120 121

	
121 122
    int maxNodeId() const { return _node_num - 1; }
122 123
    int maxEdgeId() const { return _edge_num - 1; }
123 124
    int maxArcId() const { return 2 * _edge_num - 1; }
124 125

	
125 126
    static Node nodeFromId(int id) { return Node(id);}
126 127
    static Edge edgeFromId(int id) { return Edge(id);}
127 128
    static Arc arcFromId(int id) { return Arc(id);}
128 129

	
129 130
    typedef True FindEdgeTag;
131
    typedef True FindArcTag;
130 132

	
131 133
    Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
132 134
      if (prev != INVALID) return INVALID;
133 135
      if (v._id > u._id) {
134 136
        if (v._id - u._id == _width)
135 137
          return Edge(u._id);
136 138
        if (v._id - u._id == 1 && u._id % _width < _width - 1) {
137 139
          return Edge(u._id / _width * (_width - 1) +
138 140
                      u._id % _width + _edge_limit);
139 141
        }
140 142
      } else {
141 143
        if (u._id - v._id == _width)
142 144
          return Edge(v._id);
143 145
        if (u._id - v._id == 1 && v._id % _width < _width - 1) {
144 146
          return Edge(v._id / _width * (_width - 1) +
145 147
                      v._id % _width + _edge_limit);
146 148
        }
147 149
      }
148 150
      return INVALID;
149 151
    }
150 152

	
151 153
    Arc findArc(Node u, Node v, Arc prev = INVALID) const {
152 154
      if (prev != INVALID) return INVALID;
153 155
      if (v._id > u._id) {
Ignore white space 6 line context
... ...
@@ -46,49 +46,49 @@
46 46
    };
47 47
    struct ArcT
48 48
    {
49 49
      int target, source, next_in, next_out;
50 50
      ArcT() {}
51 51
    };
52 52

	
53 53
    std::vector<NodeT> nodes;
54 54
    std::vector<ArcT> arcs;
55 55

	
56 56
  public:
57 57

	
58 58
    typedef SmartDigraphBase Graph;
59 59

	
60 60
    class Node;
61 61
    class Arc;
62 62

	
63 63
  public:
64 64

	
65 65
    SmartDigraphBase() : nodes(), arcs() { }
66 66
    SmartDigraphBase(const SmartDigraphBase &_g)
67 67
      : nodes(_g.nodes), arcs(_g.arcs) { }
68 68

	
69 69
    typedef True NodeNumTag;
70
    typedef True EdgeNumTag;
70
    typedef True ArcNumTag;
71 71

	
72 72
    int nodeNum() const { return nodes.size(); }
73 73
    int arcNum() const { return arcs.size(); }
74 74

	
75 75
    int maxNodeId() const { return nodes.size()-1; }
76 76
    int maxArcId() const { return arcs.size()-1; }
77 77

	
78 78
    Node addNode() {
79 79
      int n = nodes.size();
80 80
      nodes.push_back(NodeT());
81 81
      nodes[n].first_in = -1;
82 82
      nodes[n].first_out = -1;
83 83
      return Node(n);
84 84
    }
85 85

	
86 86
    Arc addArc(Node u, Node v) {
87 87
      int n = arcs.size();
88 88
      arcs.push_back(ArcT());
89 89
      arcs[n].source = u._id;
90 90
      arcs[n].target = v._id;
91 91
      arcs[n].next_out = nodes[u._id].first_out;
92 92
      arcs[n].next_in = nodes[v._id].first_in;
93 93
      nodes[u._id].first_out = nodes[v._id].first_in = n;
94 94

	
0 comments (0 inline)