1 | // -*- c++ -*- |
---|
2 | #ifndef HUGO_LIST_GRAPH_H |
---|
3 | #define HUGO_LIST_GRAPH_H |
---|
4 | |
---|
5 | #include <iostream> |
---|
6 | #include <vector> |
---|
7 | |
---|
8 | #include "invalid.h" |
---|
9 | |
---|
10 | #include "edge_map_registry.h" |
---|
11 | #include "node_map_registry.h" |
---|
12 | #include "edge_map_base.h" |
---|
13 | #include "node_map_base.h" |
---|
14 | #include "vector_map.h" |
---|
15 | |
---|
16 | namespace hugo { |
---|
17 | |
---|
18 | template <typename It> |
---|
19 | int count(It it) { |
---|
20 | int i=0; |
---|
21 | for( ; it.valid(); ++it) { ++i; } |
---|
22 | return i; |
---|
23 | } |
---|
24 | |
---|
25 | class ListGraph { |
---|
26 | class node_item; |
---|
27 | class edge_item; |
---|
28 | public: |
---|
29 | class Node; |
---|
30 | class NodeIt; |
---|
31 | class Edge; |
---|
32 | class EdgeIt; |
---|
33 | class OutEdgeIt; |
---|
34 | class InEdgeIt; |
---|
35 | class SymEdgeIt; |
---|
36 | |
---|
37 | // template <typename T> class NodeMap; |
---|
38 | // template <typename T> class EdgeMap; |
---|
39 | private: |
---|
40 | // template <typename T> friend class NodeMap; |
---|
41 | // template <typename T> friend class EdgeMap; |
---|
42 | |
---|
43 | private: |
---|
44 | |
---|
45 | NodeMapRegistry<ListGraph, Node> node_maps(*this); |
---|
46 | EdgeMapRegistry<ListGraph, Edge> edge_maps(*this); |
---|
47 | |
---|
48 | public: |
---|
49 | |
---|
50 | |
---|
51 | template <typename T> |
---|
52 | class NodeMap : public VectorMap<ListGraph, Node, T, NodeMapBase> { |
---|
53 | public: |
---|
54 | NodeMap(ListGraph& g) : VectorMap<ListGraph, Node, T, NodeMapBase>(g) {} |
---|
55 | }; |
---|
56 | |
---|
57 | EdgeMapRegistry<ListGraph, Edge> edge_maps; |
---|
58 | |
---|
59 | template <typename T> |
---|
60 | class EdgeMap : public VectorMap<ListGraph, Edge, T, EdgeMapBase> {}; |
---|
61 | |
---|
62 | |
---|
63 | int node_id; |
---|
64 | int edge_id; |
---|
65 | int _node_num; |
---|
66 | int _edge_num; |
---|
67 | |
---|
68 | node_item* _first_node; |
---|
69 | node_item* _last_node; |
---|
70 | |
---|
71 | class node_item { |
---|
72 | friend class ListGraph; |
---|
73 | template <typename T> friend class NodeMap; |
---|
74 | |
---|
75 | friend class Node; |
---|
76 | friend class NodeIt; |
---|
77 | friend class Edge; |
---|
78 | friend class EdgeIt; |
---|
79 | friend class OutEdgeIt; |
---|
80 | friend class InEdgeIt; |
---|
81 | friend class SymEdgeIt; |
---|
82 | friend std::ostream& operator<<(std::ostream& os, const Node& i); |
---|
83 | friend std::ostream& operator<<(std::ostream& os, const Edge& i); |
---|
84 | //ListGraph* G; |
---|
85 | int id; |
---|
86 | edge_item* _first_out_edge; |
---|
87 | edge_item* _last_out_edge; |
---|
88 | edge_item* _first_in_edge; |
---|
89 | edge_item* _last_in_edge; |
---|
90 | node_item* _next_node; |
---|
91 | node_item* _prev_node; |
---|
92 | public: |
---|
93 | node_item() { } |
---|
94 | }; |
---|
95 | |
---|
96 | class edge_item { |
---|
97 | friend class ListGraph; |
---|
98 | template <typename T> friend class EdgeMap; |
---|
99 | |
---|
100 | friend class Node; |
---|
101 | friend class NodeIt; |
---|
102 | friend class Edge; |
---|
103 | friend class EdgeIt; |
---|
104 | friend class OutEdgeIt; |
---|
105 | friend class InEdgeIt; |
---|
106 | friend class SymEdgeIt; |
---|
107 | friend std::ostream& operator<<(std::ostream& os, const Edge& i); |
---|
108 | //ListGraph* G; |
---|
109 | int id; |
---|
110 | node_item* _tail; |
---|
111 | node_item* _head; |
---|
112 | edge_item* _next_out; |
---|
113 | edge_item* _prev_out; |
---|
114 | edge_item* _next_in; |
---|
115 | edge_item* _prev_in; |
---|
116 | public: |
---|
117 | edge_item() { } |
---|
118 | }; |
---|
119 | |
---|
120 | node_item* _add_node() { |
---|
121 | node_item* p=new node_item; |
---|
122 | p->id=node_id++; |
---|
123 | p->_first_out_edge=0; |
---|
124 | p->_last_out_edge=0; |
---|
125 | p->_first_in_edge=0; |
---|
126 | p->_last_in_edge=0; |
---|
127 | p->_prev_node=_last_node; |
---|
128 | p->_next_node=0; |
---|
129 | if (_last_node) _last_node->_next_node=p; |
---|
130 | _last_node=p; |
---|
131 | if (!_first_node) _first_node=p; |
---|
132 | |
---|
133 | ++_node_num; |
---|
134 | return p; |
---|
135 | } |
---|
136 | |
---|
137 | edge_item* _add_edge(node_item* _tail, node_item* _head) { |
---|
138 | edge_item* e=new edge_item; |
---|
139 | e->id=edge_id++; |
---|
140 | e->_tail=_tail; |
---|
141 | e->_head=_head; |
---|
142 | |
---|
143 | e->_prev_out=_tail->_last_out_edge; |
---|
144 | if (_tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e; |
---|
145 | _tail->_last_out_edge=e; |
---|
146 | if (!_tail->_first_out_edge) _tail->_first_out_edge=e; |
---|
147 | e->_next_out=0; |
---|
148 | |
---|
149 | e->_prev_in=_head->_last_in_edge; |
---|
150 | if (_head->_last_in_edge) (_head->_last_in_edge)->_next_in=e; |
---|
151 | _head->_last_in_edge=e; |
---|
152 | if (!_head->_first_in_edge) { _head->_first_in_edge=e; } |
---|
153 | e->_next_in=0; |
---|
154 | |
---|
155 | ++_edge_num; |
---|
156 | return e; |
---|
157 | } |
---|
158 | |
---|
159 | //deletes a node which has no out edge and no in edge |
---|
160 | void _delete_node(node_item* v) { |
---|
161 | if (v->_next_node) (v->_next_node)->_prev_node=v->_prev_node; else |
---|
162 | _last_node=v->_prev_node; |
---|
163 | if (v->_prev_node) (v->_prev_node)->_next_node=v->_next_node; else |
---|
164 | _first_node=v->_next_node; |
---|
165 | |
---|
166 | delete v; |
---|
167 | --_node_num; |
---|
168 | } |
---|
169 | |
---|
170 | void _delete_edge(edge_item* e) { |
---|
171 | if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else |
---|
172 | (e->_tail)->_last_out_edge=e->_prev_out; |
---|
173 | if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else |
---|
174 | (e->_tail)->_first_out_edge=e->_next_out; |
---|
175 | if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else |
---|
176 | (e->_head)->_last_in_edge=e->_prev_in; |
---|
177 | if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else |
---|
178 | (e->_head)->_first_in_edge=e->_next_in; |
---|
179 | |
---|
180 | delete e; |
---|
181 | --_edge_num; |
---|
182 | } |
---|
183 | |
---|
184 | void _set_tail(edge_item* e, node_item* _tail) { |
---|
185 | if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else |
---|
186 | (e->_tail)->_last_out_edge=e->_prev_out; |
---|
187 | if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else |
---|
188 | (e->_tail)->_first_out_edge=e->_next_out; |
---|
189 | |
---|
190 | e->_tail=_tail; |
---|
191 | |
---|
192 | e->_prev_out=_tail->_last_out_edge; |
---|
193 | if (_tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e; |
---|
194 | _tail->_last_out_edge=e; |
---|
195 | if (!_tail->_first_out_edge) _tail->_first_out_edge=e; |
---|
196 | e->_next_out=0; |
---|
197 | } |
---|
198 | |
---|
199 | void _set_head(edge_item* e, node_item* _head) { |
---|
200 | if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else |
---|
201 | (e->_head)->_last_in_edge=e->_prev_in; |
---|
202 | if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else |
---|
203 | (e->_head)->_first_in_edge=e->_next_in; |
---|
204 | |
---|
205 | e->_head=_head; |
---|
206 | |
---|
207 | e->_prev_in=_head->_last_in_edge; |
---|
208 | if (_head->_last_in_edge) (_head->_last_in_edge)->_next_in=e; |
---|
209 | _head->_last_in_edge=e; |
---|
210 | if (!_head->_first_in_edge) { _head->_first_in_edge=e; } |
---|
211 | e->_next_in=0; |
---|
212 | } |
---|
213 | |
---|
214 | public: |
---|
215 | |
---|
216 | /* default constructor */ |
---|
217 | |
---|
218 | ListGraph() : node_id(0), edge_id(0), _node_num(0), _edge_num(0), _first_node(0), _last_node(0) { } |
---|
219 | |
---|
220 | ~ListGraph() { |
---|
221 | while (first<NodeIt>().valid()) erase(first<NodeIt>()); |
---|
222 | } |
---|
223 | |
---|
224 | int nodeNum() const { return _node_num; } |
---|
225 | int edgeNum() const { return _edge_num; } |
---|
226 | |
---|
227 | /* functions to construct iterators from the graph, or from each other */ |
---|
228 | |
---|
229 | //NodeIt firstNode() const { return NodeIt(*this); } |
---|
230 | //EdgeIt firstEdge() const { return EdgeIt(*this); } |
---|
231 | |
---|
232 | //OutEdgeIt firstOutEdge(const Node v) const { return OutEdgeIt(v); } |
---|
233 | //InEdgeIt firstInEdge(const Node v) const { return InEdgeIt(v); } |
---|
234 | //SymEdgeIt firstSymEdge(const Node v) const { return SymEdgeIt(v); } |
---|
235 | Node tail(Edge e) const { return e.tailNode(); } |
---|
236 | Node head(Edge e) const { return e.headNode(); } |
---|
237 | |
---|
238 | Node aNode(const OutEdgeIt& e) const { return e.aNode(); } |
---|
239 | Node aNode(const InEdgeIt& e) const { return e.aNode(); } |
---|
240 | Node aNode(const SymEdgeIt& e) const { return e.aNode(); } |
---|
241 | |
---|
242 | Node bNode(const OutEdgeIt& e) const { return e.bNode(); } |
---|
243 | Node bNode(const InEdgeIt& e) const { return e.bNode(); } |
---|
244 | Node bNode(const SymEdgeIt& e) const { return e.bNode(); } |
---|
245 | |
---|
246 | //Node invalid_node() { return Node(); } |
---|
247 | //Edge invalid_edge() { return Edge(); } |
---|
248 | //OutEdgeIt invalid_out_edge() { return OutEdgeIt(); } |
---|
249 | //InEdgeIt invalid_in_edge() { return InEdgeIt(); } |
---|
250 | //SymEdgeIt invalid_sym_edge() { return SymEdgeIt(); } |
---|
251 | |
---|
252 | /* same methods in other style */ |
---|
253 | /* for experimental purpose */ |
---|
254 | |
---|
255 | NodeIt& /*getF*/first(NodeIt& v) const { |
---|
256 | v=NodeIt(*this); return v; } |
---|
257 | EdgeIt& /*getF*/first(EdgeIt& e) const { |
---|
258 | e=EdgeIt(*this); return e; } |
---|
259 | OutEdgeIt& /*getF*/first(OutEdgeIt& e, Node v) const { |
---|
260 | e=OutEdgeIt(*this, v); return e; } |
---|
261 | InEdgeIt& /*getF*/first(InEdgeIt& e, Node v) const { |
---|
262 | e=InEdgeIt(*this, v); return e; } |
---|
263 | SymEdgeIt& /*getF*/first(SymEdgeIt& e, Node v) const { |
---|
264 | e=SymEdgeIt(*this, v); return e; } |
---|
265 | //void getTail(Node& n, const Edge& e) const { n=tail(e); } |
---|
266 | //void getHead(Node& n, const Edge& e) const { n=head(e); } |
---|
267 | |
---|
268 | //void getANode(Node& n, const OutEdgeIt& e) const { n=e.aNode(); } |
---|
269 | //void getANode(Node& n, const InEdgeIt& e) const { n=e.aNode(); } |
---|
270 | //void getANode(Node& n, const SymEdgeIt& e) const { n=e.aNode(); } |
---|
271 | //void getBNode(Node& n, const OutEdgeIt& e) const { n=e.bNode(); } |
---|
272 | //void getBNode(Node& n, const InEdgeIt& e) const { n=e.bNode(); } |
---|
273 | //void getBNode(Node& n, const SymEdgeIt& e) const { n=e.bNode(); } |
---|
274 | //void get_invalid(Node& n) { n=Node(); } |
---|
275 | //void get_invalid(Edge& e) { e=Edge(); } |
---|
276 | //void get_invalid(OutEdgeIt& e) { e=OutEdgeIt(); } |
---|
277 | //void get_invalid(InEdgeIt& e) { e=InEdgeIt(); } |
---|
278 | //void get_invalid(SymEdgeIt& e) { e=SymEdgeIt(); } |
---|
279 | |
---|
280 | template< typename It > |
---|
281 | It first() const { |
---|
282 | It e; |
---|
283 | /*getF*/first(e); |
---|
284 | return e; |
---|
285 | } |
---|
286 | |
---|
287 | template< typename It > |
---|
288 | It first(Node v) const { |
---|
289 | It e; |
---|
290 | /*getF*/first(e, v); |
---|
291 | return e; |
---|
292 | } |
---|
293 | |
---|
294 | bool valid(Node n) const { return n.valid(); } |
---|
295 | bool valid(Edge e) const { return e.valid(); } |
---|
296 | |
---|
297 | template <typename It> It getNext(It it) const { |
---|
298 | It tmp(it); return next(tmp); } |
---|
299 | template <typename It> It& next(It& it) const { return ++it; } |
---|
300 | |
---|
301 | |
---|
302 | /* for getting id's of graph objects */ |
---|
303 | /* these are important for the implementation of property vectors */ |
---|
304 | |
---|
305 | int id(Node v) const { return v.node->id; } |
---|
306 | int id(Edge e) const { return e.edge->id; } |
---|
307 | |
---|
308 | /* adding nodes and edges */ |
---|
309 | |
---|
310 | Node addNode() { |
---|
311 | Node n = _add_node(); |
---|
312 | node_maps.add(n); |
---|
313 | return n; |
---|
314 | } |
---|
315 | Edge addEdge(Node u, Node v) { |
---|
316 | Edge e = _add_edge(u.node, v.node); |
---|
317 | edge_maps.add(e); |
---|
318 | return e; |
---|
319 | } |
---|
320 | |
---|
321 | void erase(Node i) { |
---|
322 | node_maps.erase(i); |
---|
323 | while (first<OutEdgeIt>(i).valid()) erase(first<OutEdgeIt>(i)); |
---|
324 | while (first<InEdgeIt>(i).valid()) erase(first<InEdgeIt>(i)); |
---|
325 | _delete_node(i.node); |
---|
326 | } |
---|
327 | |
---|
328 | void erase(Edge e) { |
---|
329 | edge_maps.erase(e); |
---|
330 | _delete_edge(e.edge); |
---|
331 | } |
---|
332 | |
---|
333 | void clear() { |
---|
334 | while (first<NodeIt>().valid()) erase(first<NodeIt>()); |
---|
335 | } |
---|
336 | |
---|
337 | void setTail(Edge e, Node tail) { |
---|
338 | _set_tail(e.edge, tail.node); |
---|
339 | } |
---|
340 | |
---|
341 | void setHead(Edge e, Node head) { |
---|
342 | _set_head(e.edge, head.node); |
---|
343 | } |
---|
344 | |
---|
345 | /* stream operations, for testing purpose */ |
---|
346 | |
---|
347 | friend std::ostream& operator<<(std::ostream& os, const Node& i) { |
---|
348 | os << i.node->id; return os; |
---|
349 | } |
---|
350 | friend std::ostream& operator<<(std::ostream& os, const Edge& i) { |
---|
351 | os << "(" << i.edge->_tail->id << "--" << i.edge->id << "->" << i.edge->_head->id << ")"; |
---|
352 | return os; |
---|
353 | } |
---|
354 | |
---|
355 | class Node { |
---|
356 | friend class ListGraph; |
---|
357 | template <typename T> friend class NodeMap; |
---|
358 | |
---|
359 | friend class Edge; |
---|
360 | friend class OutEdgeIt; |
---|
361 | friend class InEdgeIt; |
---|
362 | friend class SymEdgeIt; |
---|
363 | //public: //FIXME: It is required by op= of NodeIt |
---|
364 | protected: |
---|
365 | node_item* node; |
---|
366 | protected: |
---|
367 | friend int ListGraph::id(Node v) const; |
---|
368 | public: |
---|
369 | Node() /*: node(0)*/ { } |
---|
370 | Node(const Invalid&) : node(0) { } |
---|
371 | protected: |
---|
372 | Node(node_item* _node) : node(_node) { } |
---|
373 | bool valid() const { return (node); } |
---|
374 | public: |
---|
375 | //void makeInvalid() { node=0; } |
---|
376 | friend bool operator==(Node u, Node v) { return v.node==u.node; } |
---|
377 | friend bool operator!=(Node u, Node v) { return v.node!=u.node; } |
---|
378 | friend std::ostream& operator<<(std::ostream& os, const Node& i); |
---|
379 | }; |
---|
380 | |
---|
381 | class NodeIt : public Node { |
---|
382 | friend class ListGraph; |
---|
383 | //protected: |
---|
384 | public: //for everybody but marci |
---|
385 | NodeIt(const ListGraph& G) : Node(G._first_node) { } |
---|
386 | public: |
---|
387 | NodeIt() : Node() { } |
---|
388 | NodeIt(const Invalid& i) : Node(i) { } |
---|
389 | protected: |
---|
390 | NodeIt(node_item* v) : Node(v) { } |
---|
391 | NodeIt& operator++() { node=node->_next_node; return *this; } |
---|
392 | //FIXME:: |
---|
393 | // NodeIt& operator=(const Node& e) |
---|
394 | // { node=e.node; return *this; } |
---|
395 | }; |
---|
396 | |
---|
397 | class Edge { |
---|
398 | friend class ListGraph; |
---|
399 | template <typename T> friend class EdgeMap; |
---|
400 | |
---|
401 | friend class Node; |
---|
402 | friend class NodeIt; |
---|
403 | protected: |
---|
404 | edge_item* edge; |
---|
405 | friend int ListGraph::id(Edge e) const; |
---|
406 | public: |
---|
407 | Edge() /*: edge(0)*/ { } |
---|
408 | Edge(const Invalid&) : edge(0) { } |
---|
409 | //Edge() { } |
---|
410 | protected: |
---|
411 | Edge(edge_item* _edge) : edge(_edge) { } |
---|
412 | bool valid() const { return (edge); } |
---|
413 | public: |
---|
414 | //void makeInvalid() { edge=0; } |
---|
415 | friend bool operator==(Edge u, Edge v) { return v.edge==u.edge; } |
---|
416 | friend bool operator!=(Edge u, Edge v) { return v.edge!=u.edge; } |
---|
417 | protected: |
---|
418 | Node tailNode() const { return Node(edge->_tail); } |
---|
419 | Node headNode() const { return Node(edge->_head); } |
---|
420 | public: |
---|
421 | friend std::ostream& operator<<(std::ostream& os, const Edge& i); |
---|
422 | }; |
---|
423 | |
---|
424 | class EdgeIt : public Edge { |
---|
425 | friend class ListGraph; |
---|
426 | //protected: |
---|
427 | public: //for alpar |
---|
428 | EdgeIt(const ListGraph& G) { |
---|
429 | node_item* v=G._first_node; |
---|
430 | if (v) edge=v->_first_out_edge; else edge=0; |
---|
431 | while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; } |
---|
432 | } |
---|
433 | public: |
---|
434 | EdgeIt() : Edge() { } |
---|
435 | EdgeIt(const Invalid& i) : Edge(i) { } |
---|
436 | protected: |
---|
437 | EdgeIt(edge_item* _e) : Edge(_e) { } |
---|
438 | EdgeIt& operator++() { |
---|
439 | node_item* v=edge->_tail; |
---|
440 | edge=edge->_next_out; |
---|
441 | while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; } |
---|
442 | return *this; |
---|
443 | } |
---|
444 | }; |
---|
445 | |
---|
446 | class OutEdgeIt : public Edge { |
---|
447 | friend class ListGraph; |
---|
448 | //node_item* v; |
---|
449 | //protected: |
---|
450 | protected: //for alpar |
---|
451 | OutEdgeIt(const Node& _v) /*: v(_v.node)*/ { edge=_v.node->_first_out_edge; } |
---|
452 | public: |
---|
453 | OutEdgeIt() : Edge()/*, v(0)*/ { } |
---|
454 | OutEdgeIt(const Invalid& i) : Edge(i) { } |
---|
455 | OutEdgeIt(const ListGraph&, Node _v) /*: v(_v.node)*/ { edge=_v.node->_first_out_edge; } |
---|
456 | protected: |
---|
457 | OutEdgeIt& operator++() { edge=edge->_next_out; return *this; } |
---|
458 | protected: |
---|
459 | Node aNode() const { return Node(edge->_tail); } |
---|
460 | Node bNode() const { return Node(edge->_head); } |
---|
461 | }; |
---|
462 | |
---|
463 | class InEdgeIt : public Edge { |
---|
464 | friend class ListGraph; |
---|
465 | //node_item* v; |
---|
466 | //protected: |
---|
467 | protected: //for alpar |
---|
468 | InEdgeIt(const Node& _v) /*: v(_v.node)*/ { edge=_v.node->_first_in_edge; } |
---|
469 | public: |
---|
470 | InEdgeIt() : Edge()/*, v(0)*/ { } |
---|
471 | InEdgeIt(const Invalid& i) : Edge(i) { } |
---|
472 | InEdgeIt(const ListGraph&, Node _v) /*: v(_v.node)*/ { edge=_v.node->_first_in_edge; } |
---|
473 | protected: |
---|
474 | InEdgeIt& operator++() { edge=edge->_next_in; return *this; } |
---|
475 | protected: |
---|
476 | Node aNode() const { return Node(edge->_head); } |
---|
477 | Node bNode() const { return Node(edge->_tail); } |
---|
478 | }; |
---|
479 | |
---|
480 | class SymEdgeIt : public Edge { |
---|
481 | friend class ListGraph; |
---|
482 | bool out_or_in; //1 iff out, 0 iff in |
---|
483 | //node_item* v; |
---|
484 | //protected: |
---|
485 | public: //for alpar |
---|
486 | SymEdgeIt(const Node& _v) /*: v(_v.node)*/ { |
---|
487 | out_or_in=1; |
---|
488 | edge=_v.node->_first_out_edge; |
---|
489 | if (!edge) { edge=_v.node->_first_in_edge; out_or_in=0; } |
---|
490 | } |
---|
491 | public: |
---|
492 | SymEdgeIt() : Edge() /*, v(0)*/ { } |
---|
493 | SymEdgeIt(const Invalid& i) : Edge(i) { } |
---|
494 | SymEdgeIt(const ListGraph&, Node _v) /*: v(_v.node)*/ { |
---|
495 | out_or_in=1; |
---|
496 | edge=_v.node->_first_out_edge; |
---|
497 | if (!edge) { edge=_v.node->_first_in_edge; out_or_in=0; } |
---|
498 | } |
---|
499 | protected: |
---|
500 | SymEdgeIt& operator++() { |
---|
501 | if (out_or_in) { |
---|
502 | node_item* v=edge->_tail; |
---|
503 | edge=edge->_next_out; |
---|
504 | if (!edge) { out_or_in=0; edge=v->_first_in_edge; } |
---|
505 | } else { |
---|
506 | edge=edge->_next_in; |
---|
507 | } |
---|
508 | return *this; |
---|
509 | } |
---|
510 | protected: |
---|
511 | Node aNode() const { |
---|
512 | return (out_or_in) ? Node(edge->_tail) : Node(edge->_head); } |
---|
513 | Node bNode() const { |
---|
514 | return (out_or_in) ? Node(edge->_head) : Node(edge->_tail); } |
---|
515 | }; |
---|
516 | |
---|
517 | }; |
---|
518 | |
---|
519 | // template< typename T > |
---|
520 | // T ListGraph::first() const { |
---|
521 | // std::cerr << "Invalid use of template<typemane T> T ListGraph::first<T>();" << std::endl; |
---|
522 | // return T(); |
---|
523 | // } |
---|
524 | |
---|
525 | // template<> |
---|
526 | // ListGraph::NodeIt ListGraph::first<ListGraph::NodeIt>() const { |
---|
527 | // return firstNode(); |
---|
528 | // } |
---|
529 | |
---|
530 | // template<> |
---|
531 | // ListGraph::EdgeIt ListGraph::first<ListGraph::EdgeIt>() const { |
---|
532 | // return firstEdge(); |
---|
533 | // } |
---|
534 | |
---|
535 | // template< typename T > |
---|
536 | // T ListGraph::first(ListGraph::Node v) const { |
---|
537 | // std::cerr << "Invalid use of template<typemane T> T ListGraph::first<T>(ListGRaph::Node);" << std::endl; |
---|
538 | // return T(); |
---|
539 | // } |
---|
540 | |
---|
541 | // template<> |
---|
542 | // ListGraph::OutEdgeIt ListGraph::first<ListGraph::OutEdgeIt>(const ListGraph::Node v) const { |
---|
543 | // return firstOutEdge(v); |
---|
544 | // } |
---|
545 | |
---|
546 | // template<> |
---|
547 | // ListGraph::InEdgeIt ListGraph::first<ListGraph::InEdgeIt>(const ListGraph::Node v) const { |
---|
548 | // return firstInEdge(v); |
---|
549 | // } |
---|
550 | |
---|
551 | // template<> |
---|
552 | // ListGraph::SymEdgeIt ListGraph::first<ListGraph::SymEdgeIt>(const ListGraph::Node v) const { |
---|
553 | // return firstSymEdge(v); |
---|
554 | // } |
---|
555 | |
---|
556 | |
---|
557 | } //namespace hugo |
---|
558 | |
---|
559 | #endif //HUGO_LIST_GRAPH_H |
---|