# HG changeset patch
# User gyorokp
# Date 1270891385 -7200
# Node ID 873b8d0104e73ab66cacb90ff7e6e2de6122eb81
# Parent c8e6952a00ebefcb7d775719f45101faebf81ea4
Rewrote CommonNodesIt and CommonFacesIt using std::set (#363)
diff -r c8e6952a00eb -r 873b8d0104e7 lemon/planar_graph.h
|
a
|
b
|
|
| 30 | 30 | |
| 31 | 31 | #include <vector> |
| 32 | 32 | #include <list> |
| | 33 | #include <set> |
| 33 | 34 | |
| 34 | 35 | #ifdef REMOVE_BEFORE_RELEASE |
| 35 | 36 | #include <iostream> |
| … |
… |
|
| 1283 | 1284 | class CommonFacesIt : public Face { |
| 1284 | 1285 | const Graph* _graph; |
| 1285 | 1286 | const Node _n1, _n2; |
| 1286 | | Arc _i1, _i2; |
| | 1287 | Arc _i2; |
| | 1288 | std::set<Face> _f1; |
| 1287 | 1289 | public: |
| 1288 | 1290 | |
| 1289 | 1291 | CommonFacesIt() {} |
| … |
… |
|
| 1291 | 1293 | CommonFacesIt(Invalid i) : Face(i) { } |
| 1292 | 1294 | |
| 1293 | 1295 | explicit CommonFacesIt(const Graph& graph, Node n1, Node n2) : _graph( |
| 1294 | | &graph), _n1(n1), _n2(n2), _i1(), _i2(){ |
| | 1296 | &graph), _n1(n1), _n2(n2), _i2(), _f1(){ |
| | 1297 | Arc _i1; |
| 1295 | 1298 | _graph->firstOut(_i1,_n1); |
| | 1299 | while (_i1 != INVALID) { |
| | 1300 | _f1.insert(_graph->leftFace(_i1)); |
| | 1301 | _graph->nextOut(_i1); |
| | 1302 | } |
| 1296 | 1303 | _graph->firstOut(_i2,_n2); |
| 1297 | | while (_i1 != INVALID && _graph->leftFace(_i1) != _graph->leftFace(_i2)) |
| 1298 | | { |
| | 1304 | _graph->firstOut(_i2,_n2); |
| | 1305 | while (_i2 != INVALID && _f1.count(_graph->leftFace(_i2)) == 0) |
| 1299 | 1306 | _graph->nextOut(_i2); |
| 1300 | | if (_i2 == INVALID) { |
| 1301 | | _graph->nextOut(_i1); |
| 1302 | | _graph->firstOut(_i2,_n2); |
| 1303 | | } |
| 1304 | | } |
| 1305 | | static_cast<Face&>(*this) = (_i1 != INVALID)?_graph->leftFace(_i1): |
| | 1307 | static_cast<Face&>(*this) = (_i2 != INVALID)?_graph->leftFace(_i2): |
| 1306 | 1308 | INVALID; |
| 1307 | 1309 | } |
| 1308 | 1310 | |
| 1309 | 1311 | CommonFacesIt& operator++() { |
| 1310 | 1312 | _graph->nextOut(_i2); |
| 1311 | | if (_i2 == INVALID) { |
| 1312 | | _graph->nextOut(_i1); |
| 1313 | | _graph->firstOut(_i2,_n2); |
| 1314 | | } |
| 1315 | | while (_i1 != INVALID && _graph->leftFace(_i1) != _graph->leftFace(_i2)) |
| 1316 | | { |
| | 1313 | while (_i2 != INVALID && _f1.count(_graph->leftFace(_i2)) == 0) |
| 1317 | 1314 | _graph->nextOut(_i2); |
| 1318 | | if (_i2 == INVALID) { |
| 1319 | | _graph->nextOut(_i1); |
| 1320 | | _graph->firstOut(_i2,_n2); |
| 1321 | | } |
| 1322 | | } |
| 1323 | | static_cast<Face&>(*this) = (_i1 != INVALID)?_graph->leftFace(_i1): |
| | 1315 | static_cast<Face&>(*this) = (_i2 != INVALID)?_graph->leftFace(_i2): |
| 1324 | 1316 | INVALID; |
| 1325 | 1317 | return *this; |
| 1326 | 1318 | } |
| … |
… |
|
| 1333 | 1325 | class CommonNodesIt : public Node { |
| 1334 | 1326 | const Graph* _graph; |
| 1335 | 1327 | const Face _f1, _f2; |
| 1336 | | Arc _i1, _i2; |
| | 1328 | Arc _i2; |
| | 1329 | std::set<Node> _ns; |
| 1337 | 1330 | public: |
| 1338 | 1331 | |
| 1339 | 1332 | CommonNodesIt() {} |
| … |
… |
|
| 1341 | 1334 | CommonNodesIt(Invalid i) : Face(i) { } |
| 1342 | 1335 | |
| 1343 | 1336 | explicit CommonNodesIt(const Graph& graph, Face f1, Face f2) : _graph( |
| 1344 | | &graph), _f1(f1), _f2(f2), _i1(), _i2(){ |
| | 1337 | &graph), _f1(f1), _f2(f2), _i2(), _ns(){ |
| | 1338 | Arc _i1; |
| 1345 | 1339 | _graph->firstCwF(_i1,_f1); |
| | 1340 | while (_i1 != INVALID) { |
| | 1341 | _ns.insert(_graph->source(_i1)); |
| | 1342 | _graph->nextCwF(_i1); |
| | 1343 | } |
| | 1344 | |
| 1346 | 1345 | _graph->firstCwF(_i2,_f2); |
| 1347 | | while (_i1 != INVALID && _graph->source(_i1) != _graph->source(_i2)) |
| 1348 | | { |
| | 1346 | while (_i2 != INVALID && _ns.count(_graph->source(_i2)) == 0) |
| 1349 | 1347 | _graph->nextCwF(_i2); |
| 1350 | | if (_i2 == INVALID) { |
| 1351 | | _graph->nextCwF(_i1); |
| 1352 | | _graph->firstCwF(_i2,_f2); |
| 1353 | | } |
| 1354 | | } |
| 1355 | | static_cast<Node&>(*this) = (_i1 != INVALID)?_graph->source(_i1): |
| | 1348 | static_cast<Node&>(*this) = (_i2 != INVALID)?_graph->source(_i2): |
| 1356 | 1349 | INVALID; |
| 1357 | 1350 | } |
| 1358 | 1351 | |
| 1359 | 1352 | CommonNodesIt& operator++() { |
| 1360 | 1353 | _graph->nextCwF(_i2); |
| 1361 | | if (_i2 == INVALID) { |
| 1362 | | _graph->nextCwF(_i1); |
| 1363 | | _graph->firstCwF(_i2,_f2); |
| 1364 | | } |
| 1365 | | while (_i1 != INVALID && _graph->source(_i1) != _graph->source(_i2)) |
| 1366 | | { |
| | 1354 | while (_i2 != INVALID && _ns.count(_graph->source(_i2)) == 0) |
| 1367 | 1355 | _graph->nextCwF(_i2); |
| 1368 | | if (_i2 == INVALID) { |
| 1369 | | _graph->nextCwF(_i1); |
| 1370 | | _graph->firstCwF(_i2,_f2); |
| 1371 | | } |
| 1372 | | } |
| 1373 | | static_cast<Node&>(*this) = (_i1 != INVALID)?_graph->source(_i1): |
| | 1356 | static_cast<Node&>(*this) = (_i2 != INVALID)?_graph->source(_i2): |
| 1374 | 1357 | INVALID; |
| 1375 | 1358 | return *this; |
| 1376 | 1359 | } |