109 |
109 |
110 /// \brief Starting point of the path. |
110 /// \brief Starting point of the path. |
111 /// |
111 /// |
112 /// Starting point of the path. |
112 /// Starting point of the path. |
113 /// Returns INVALID if the path is empty. |
113 /// Returns INVALID if the path is empty. |
114 GraphNode tail() const { |
114 GraphNode source() const { |
115 return empty() ? INVALID : gr->tail(edges[0]); |
115 return empty() ? INVALID : gr->source(edges[0]); |
116 } |
116 } |
117 /// \brief End point of the path. |
117 /// \brief End point of the path. |
118 /// |
118 /// |
119 /// End point of the path. |
119 /// End point of the path. |
120 /// Returns INVALID if the path is empty. |
120 /// Returns INVALID if the path is empty. |
121 GraphNode head() const { |
121 GraphNode target() const { |
122 return empty() ? INVALID : gr->head(edges[length()-1]); |
122 return empty() ? INVALID : gr->target(edges[length()-1]); |
123 } |
123 } |
124 |
124 |
125 /// \brief Initializes node or edge iterator to point to the first |
125 /// \brief Initializes node or edge iterator to point to the first |
126 /// node or edge. |
126 /// node or edge. |
127 /// |
127 /// |
137 /// \brief Initializes edge iterator to point to the edge of a given index. |
137 /// \brief Initializes edge iterator to point to the edge of a given index. |
138 EdgeIt& nth(EdgeIt &i, int n) const { |
138 EdgeIt& nth(EdgeIt &i, int n) const { |
139 return i=EdgeIt(*this, n); |
139 return i=EdgeIt(*this, n); |
140 } |
140 } |
141 |
141 |
142 /// \brief Returns node iterator pointing to the head node of the |
142 /// \brief Returns node iterator pointing to the target node of the |
143 /// given edge iterator. |
143 /// given edge iterator. |
144 NodeIt head(const EdgeIt& e) const { |
144 NodeIt target(const EdgeIt& e) const { |
145 return NodeIt(*this, e.idx+1); |
145 return NodeIt(*this, e.idx+1); |
146 } |
146 } |
147 |
147 |
148 /// \brief Returns node iterator pointing to the tail node of the |
148 /// \brief Returns node iterator pointing to the source node of the |
149 /// given edge iterator. |
149 /// given edge iterator. |
150 NodeIt tail(const EdgeIt& e) const { |
150 NodeIt source(const EdgeIt& e) const { |
151 return NodeIt(*this, e.idx); |
151 return NodeIt(*this, e.idx); |
152 } |
152 } |
153 |
153 |
154 |
154 |
155 /* Iterator classes */ |
155 /* Iterator classes */ |
228 bool valid() const { return idx!=-1; } |
228 bool valid() const { return idx!=-1; } |
229 |
229 |
230 ///Conversion to Graph::Node |
230 ///Conversion to Graph::Node |
231 operator const GraphNode& () const { |
231 operator const GraphNode& () const { |
232 if(idx >= p->length()) |
232 if(idx >= p->length()) |
233 return p->head(); |
233 return p->target(); |
234 else if(idx >= 0) |
234 else if(idx >= 0) |
235 return p->gr->tail(p->edges[idx]); |
235 return p->gr->source(p->edges[idx]); |
236 else |
236 else |
237 return INVALID; |
237 return INVALID; |
238 } |
238 } |
239 /// Next node |
239 /// Next node |
240 NodeIt& operator++() { ++idx; validate(); return *this; } |
240 NodeIt& operator++() { ++idx; validate(); return *this; } |
333 private: |
333 private: |
334 bool empty() { |
334 bool empty() { |
335 return front.empty() && back.empty() && P.empty(); |
335 return front.empty() && back.empty() && P.empty(); |
336 } |
336 } |
337 |
337 |
338 GraphNode tail() const { |
338 GraphNode source() const { |
339 if( ! front.empty() ) |
339 if( ! front.empty() ) |
340 return P.gr->tail(front[front.size()-1]); |
340 return P.gr->source(front[front.size()-1]); |
341 else if( ! P.empty() ) |
341 else if( ! P.empty() ) |
342 return P.gr->tail(P.edges[0]); |
342 return P.gr->source(P.edges[0]); |
343 else if( ! back.empty() ) |
343 else if( ! back.empty() ) |
344 return P.gr->tail(back[0]); |
344 return P.gr->source(back[0]); |
345 else |
345 else |
346 return INVALID; |
346 return INVALID; |
347 } |
347 } |
348 GraphNode head() const { |
348 GraphNode target() const { |
349 if( ! back.empty() ) |
349 if( ! back.empty() ) |
350 return P.gr->head(back[back.size()-1]); |
350 return P.gr->target(back[back.size()-1]); |
351 else if( ! P.empty() ) |
351 else if( ! P.empty() ) |
352 return P.gr->head(P.edges[P.length()-1]); |
352 return P.gr->target(P.edges[P.length()-1]); |
353 else if( ! front.empty() ) |
353 else if( ! front.empty() ) |
354 return P.gr->head(front[0]); |
354 return P.gr->target(front[0]); |
355 else |
355 else |
356 return INVALID; |
356 return INVALID; |
357 } |
357 } |
358 |
358 |
359 }; |
359 }; |
435 |
435 |
436 /// \brief Starting point of the path. |
436 /// \brief Starting point of the path. |
437 /// |
437 /// |
438 /// Starting point of the path. |
438 /// Starting point of the path. |
439 /// Returns INVALID if the path is empty. |
439 /// Returns INVALID if the path is empty. |
440 GraphNode tail() const { |
440 GraphNode source() const { |
441 return empty() ? INVALID : gr->tail(edges[0]); |
441 return empty() ? INVALID : gr->source(edges[0]); |
442 } |
442 } |
443 /// \brief End point of the path. |
443 /// \brief End point of the path. |
444 /// |
444 /// |
445 /// End point of the path. |
445 /// End point of the path. |
446 /// Returns INVALID if the path is empty. |
446 /// Returns INVALID if the path is empty. |
447 GraphNode head() const { |
447 GraphNode target() const { |
448 return empty() ? INVALID : gr->head(edges[length()-1]); |
448 return empty() ? INVALID : gr->target(edges[length()-1]); |
449 } |
449 } |
450 |
450 |
451 /// \brief Initializes node or edge iterator to point to the first |
451 /// \brief Initializes node or edge iterator to point to the first |
452 /// node or edge. |
452 /// node or edge. |
453 /// |
453 /// |
475 static |
475 static |
476 It& next(It &e) { |
476 It& next(It &e) { |
477 return ++e; |
477 return ++e; |
478 } |
478 } |
479 |
479 |
480 /// \brief Returns node iterator pointing to the head node of the |
480 /// \brief Returns node iterator pointing to the target node of the |
481 /// given edge iterator. |
481 /// given edge iterator. |
482 NodeIt head(const EdgeIt& e) const { |
482 NodeIt target(const EdgeIt& e) const { |
483 return NodeIt(*this, e.idx+1); |
483 return NodeIt(*this, e.idx+1); |
484 } |
484 } |
485 |
485 |
486 /// \brief Returns node iterator pointing to the tail node of the |
486 /// \brief Returns node iterator pointing to the source node of the |
487 /// given edge iterator. |
487 /// given edge iterator. |
488 NodeIt tail(const EdgeIt& e) const { |
488 NodeIt source(const EdgeIt& e) const { |
489 return NodeIt(*this, e.idx); |
489 return NodeIt(*this, e.idx); |
490 } |
490 } |
491 |
491 |
492 |
492 |
493 |
493 |
568 bool valid() const { return idx!=-1; } |
568 bool valid() const { return idx!=-1; } |
569 |
569 |
570 ///Conversion to Graph::Node |
570 ///Conversion to Graph::Node |
571 operator const GraphNode& () const { |
571 operator const GraphNode& () const { |
572 if(idx >= p->length()) |
572 if(idx >= p->length()) |
573 return p->head(); |
573 return p->target(); |
574 else if(idx >= 0) |
574 else if(idx >= 0) |
575 return p->gr->tail(p->edges[idx]); |
575 return p->gr->source(p->edges[idx]); |
576 else |
576 else |
577 return INVALID; |
577 return INVALID; |
578 } |
578 } |
579 /// Next node |
579 /// Next node |
580 NodeIt& operator++() { ++idx; validate(); return *this; } |
580 NodeIt& operator++() { ++idx; validate(); return *this; } |
674 private: |
674 private: |
675 bool empty() { |
675 bool empty() { |
676 return front.empty() && back.empty() && P.empty(); |
676 return front.empty() && back.empty() && P.empty(); |
677 } |
677 } |
678 |
678 |
679 GraphNode tail() const { |
679 GraphNode source() const { |
680 if( ! front.empty() ) |
680 if( ! front.empty() ) |
681 return P.gr->tail(front[front.size()-1]); |
681 return P.gr->source(front[front.size()-1]); |
682 else if( ! P.empty() ) |
682 else if( ! P.empty() ) |
683 return P.gr->tail(P.edges[0]); |
683 return P.gr->source(P.edges[0]); |
684 else if( ! back.empty() ) |
684 else if( ! back.empty() ) |
685 return P.gr->tail(back[0]); |
685 return P.gr->source(back[0]); |
686 else |
686 else |
687 return INVALID; |
687 return INVALID; |
688 } |
688 } |
689 GraphNode head() const { |
689 GraphNode target() const { |
690 if( ! back.empty() ) |
690 if( ! back.empty() ) |
691 return P.gr->head(back[back.size()-1]); |
691 return P.gr->target(back[back.size()-1]); |
692 else if( ! P.empty() ) |
692 else if( ! P.empty() ) |
693 return P.gr->head(P.edges[P.length()-1]); |
693 return P.gr->target(P.edges[P.length()-1]); |
694 else if( ! front.empty() ) |
694 else if( ! front.empty() ) |
695 return P.gr->head(front[0]); |
695 return P.gr->target(front[0]); |
696 else |
696 else |
697 return INVALID; |
697 return INVALID; |
698 } |
698 } |
699 |
699 |
700 }; |
700 }; |