Changeset 226:616bc397c83a in lemon0.x
 Timestamp:
 03/21/04 18:09:16 (16 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@323
 Location:
 src/work/klao
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/work/klao/path.h
r225 r226 11 11 12 12 #include <deque> 13 #include <algorithm> 13 14 14 15 #include <invalid.h> … … 40 41 Path(Graph &_G) : G(_G), _first(INVALID), _last(INVALID) {} 41 42 42 /// Subpath defined by two nodes 43 Path(Path const& P, NodeIt a, NodeIt b) { FIXME; } 44 /// Subpath defined by tow edges. Contains edges in [a,b) 45 Path(Path const& P, EdgeIt a, EdgeIt b) { FIXME; } 43 /// Subpath defined by two nodes. 44 /// Nodes may be in reversed order, then 45 /// we contstruct the reversed path. 46 Path(const Path &P, const NodeIt &a, const NodeIt &b); 47 /// Subpath defined by two edges. Contains edges in [a,b) 48 /// It is an error if the two edges are not in order! 49 Path(const Path &P, const EdgeIt &a, const EdgeIt &b); 46 50 47 51 size_t length() const { return edges.size(); } … … 71 75 72 76 bool isForward(const EdgeIt &e) const { return e.forw; } 77 78 /// index of a node on the path. Returns length+2 for the invalid NodeIt 79 int index(const NodeIt &n) const { return n.idx; } 80 /// index of an edge on the path. Returns length+1 for the invalid EdgeIt 81 int index(const EdgeIt &e) const { return e.it  edges.begin(); } 73 82 74 83 EdgeIt& next(EdgeIt &e) const; … … 123 132 friend class EdgeIt; 124 133 125 int idx;134 size_t idx; 126 135 bool tail; // Is this node the tail of the edge with same idx? 127 136 … … 302 311 n.idx = e.itedges.begin(); 303 312 n.tail = e.forw; 313 return n; 304 314 } 305 315 … … 378 388 } 379 389 390 // Reszut konstruktorok: 391 392 393 template<typename Gr> 394 Path<Gr>::Path(const Path &P, const EdgeIt &a, const EdgeIt &b) : 395 G(P.G), edges(a.it, b.it) // WARNING: if b.it < a.it this will blow up! 396 { 397 if( G.valid(P._first) && a.it < P.edges.end() ) { 398 _first = ( a.forw ? G.tail(*a.it) : G.head(*a.it) ); 399 if( b.it < P.edges.end() ) { 400 _last = ( b.forw ? G.tail(*b.it) : G.head(*b.it) ); 401 } 402 else { 403 _last = P._last; 404 } 405 } 406 } 407 408 409 template<typename Gr> 410 Path<Gr>::Path(const Path &P, const NodeIt &a, const NodeIt &b) : 411 G(P.G) 412 { 413 if( !P.valid(a)  !P.valid(b) ) 414 return; 415 416 int ai = a.idx, bi = b.idx; 417 if( bi<ai ) 418 swap(ai,bi); 419 420 edges.resize(biai); 421 copy(P.edges.begin()+ai, P.edges.begin()+bi, edges.begin()); 422 423 _first = P.graphNode(a); 424 _last = P.graphNode(b); 425 } 426 380 427 381 428 } // namespace hugo 
src/work/klao/path_test.cc
r225 r226 110 110 } 111 111 112 { 113 cout << "Reszut letrehozasa: [2. el, 4. el)..." << endl; 114 LPath P2(P, P.nth<EdgeIt>(1), P.nth<EdgeIt>(3)); 115 116 cout << "P2.length() == " << P2.length() << endl; 117 check(P2.length() == 2); 118 119 cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl; 120 check(P2.from() == v1); 121 cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl; 122 check(P2.to() == v3); 123 } 124 { 125 cout << "Reszut letrehozasa: [1. el, 6. el)..." << endl; 126 LPath P2(P, P.nth<EdgeIt>(0), P.nth<EdgeIt>(5)); 127 128 cout << "P2.length() == " << P2.length() << endl; 129 check(P2.length() == 5); 130 131 cout << "P2.from()==s ? " << (P2.from()==s) << endl; 132 check(P2.from() == s); 133 cout << "P2.to()==t ? " << (P2.to()==t) << endl; 134 check(P2.to() == t); 135 } 136 137 { 138 cout << "Ket pont altal megadott reszut letrehozasa: [2. pont, 4. pont]..." 139 << endl; 140 LPath P2(P, P.nth<NodeIt>(1), P.nth<NodeIt>(3)); 141 142 cout << "P2.length() == " << P2.length() << endl; 143 check(P2.length() == 2); 144 145 cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl; 146 check(P2.from() == v1); 147 cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl; 148 check(P2.to() == v3); 149 } 150 { 151 cout << "Egy pontu reszut letrehozasa: [4. pont, 4. pont]..." 152 << endl; 153 LPath P2(P, P.nth<NodeIt>(3), P.nth<NodeIt>(3)); 154 155 cout << "P2.length() == " << P2.length() << endl; 156 check(P2.length() == 0); 157 158 cout << "P2.from()==v3 ? " << (P2.from()==v3) << endl; 159 check(P2.from() == v3); 160 cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl; 161 check(P2.to() == v3); 162 } 163 { 164 cout << "Forditott ut letrehozasa: [6. pont, 1. pont]..." 165 << endl; 166 LPath P2(P, P.nth<NodeIt>(5), P.nth<NodeIt>(0)); 167 168 cout << "P2.length() == " << P2.length() << endl; 169 check(P2.length() == 5); 170 171 cout << "P2.from()==t ? " << (P2.from()==t) << endl; 172 check(P2.from() == t); 173 cout << "P2.to()==s ? " << (P2.to()==s) << endl; 174 check(P2.to() == s); 175 } 112 176 113 177
Note: See TracChangeset
for help on using the changeset viewer.