1.1 --- a/src/work/klao/path.h Sun Mar 21 16:16:08 2004 +0000
1.2 +++ b/src/work/klao/path.h Sun Mar 21 17:09:16 2004 +0000
1.3 @@ -10,6 +10,7 @@
1.4 #define HUGO_PATH_H
1.5
1.6 #include <deque>
1.7 +#include <algorithm>
1.8
1.9 #include <invalid.h>
1.10
1.11 @@ -39,10 +40,13 @@
1.12
1.13 Path(Graph &_G) : G(_G), _first(INVALID), _last(INVALID) {}
1.14
1.15 - /// Subpath defined by two nodes
1.16 - Path(Path const& P, NodeIt a, NodeIt b) { FIXME; }
1.17 - /// Subpath defined by tow edges. Contains edges in [a,b)
1.18 - Path(Path const& P, EdgeIt a, EdgeIt b) { FIXME; }
1.19 + /// Subpath defined by two nodes.
1.20 + /// Nodes may be in reversed order, then
1.21 + /// we contstruct the reversed path.
1.22 + Path(const Path &P, const NodeIt &a, const NodeIt &b);
1.23 + /// Subpath defined by two edges. Contains edges in [a,b)
1.24 + /// It is an error if the two edges are not in order!
1.25 + Path(const Path &P, const EdgeIt &a, const EdgeIt &b);
1.26
1.27 size_t length() const { return edges.size(); }
1.28 GraphNode from() const { return _first; }
1.29 @@ -71,6 +75,11 @@
1.30
1.31 bool isForward(const EdgeIt &e) const { return e.forw; }
1.32
1.33 + /// index of a node on the path. Returns length+2 for the invalid NodeIt
1.34 + int index(const NodeIt &n) const { return n.idx; }
1.35 + /// index of an edge on the path. Returns length+1 for the invalid EdgeIt
1.36 + int index(const EdgeIt &e) const { return e.it - edges.begin(); }
1.37 +
1.38 EdgeIt& next(EdgeIt &e) const;
1.39 NodeIt& next(NodeIt &n) const;
1.40 template <typename It>
1.41 @@ -122,7 +131,7 @@
1.42 friend class Path;
1.43 friend class EdgeIt;
1.44
1.45 - int idx;
1.46 + size_t idx;
1.47 bool tail; // Is this node the tail of the edge with same idx?
1.48
1.49 public:
1.50 @@ -301,6 +310,7 @@
1.51
1.52 n.idx = e.it-edges.begin();
1.53 n.tail = e.forw;
1.54 + return n;
1.55 }
1.56
1.57 template<typename Gr>
1.58 @@ -377,6 +387,43 @@
1.59 return n;
1.60 }
1.61
1.62 + // Reszut konstruktorok:
1.63 +
1.64 +
1.65 + template<typename Gr>
1.66 + Path<Gr>::Path(const Path &P, const EdgeIt &a, const EdgeIt &b) :
1.67 + G(P.G), edges(a.it, b.it) // WARNING: if b.it < a.it this will blow up!
1.68 + {
1.69 + if( G.valid(P._first) && a.it < P.edges.end() ) {
1.70 + _first = ( a.forw ? G.tail(*a.it) : G.head(*a.it) );
1.71 + if( b.it < P.edges.end() ) {
1.72 + _last = ( b.forw ? G.tail(*b.it) : G.head(*b.it) );
1.73 + }
1.74 + else {
1.75 + _last = P._last;
1.76 + }
1.77 + }
1.78 + }
1.79 +
1.80 +
1.81 + template<typename Gr>
1.82 + Path<Gr>::Path(const Path &P, const NodeIt &a, const NodeIt &b) :
1.83 + G(P.G)
1.84 + {
1.85 + if( !P.valid(a) || !P.valid(b) )
1.86 + return;
1.87 +
1.88 + int ai = a.idx, bi = b.idx;
1.89 + if( bi<ai )
1.90 + swap(ai,bi);
1.91 +
1.92 + edges.resize(bi-ai);
1.93 + copy(P.edges.begin()+ai, P.edges.begin()+bi, edges.begin());
1.94 +
1.95 + _first = P.graphNode(a);
1.96 + _last = P.graphNode(b);
1.97 + }
1.98 +
1.99
1.100 } // namespace hugo
1.101