# 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/lemon/planar_graph.h	Sun Mar 28 12:39:45 2010 +0200
+++ b/lemon/planar_graph.h	Sat Apr 10 11:23:05 2010 +0200
@@ -30,6 +30,7 @@
 
 #include <vector>
 #include <list>
+#include <set>
 
 #ifdef REMOVE_BEFORE_RELEASE
 #include <iostream>
@@ -1283,7 +1284,8 @@
   class CommonFacesIt : public Face {
       const Graph* _graph;
       const Node _n1, _n2;
-      Arc _i1, _i2;
+      Arc _i2;
+      std::set<Face> _f1;
     public:
 
       CommonFacesIt() {}
@@ -1291,36 +1293,26 @@
       CommonFacesIt(Invalid i) : Face(i) { }
 
       explicit CommonFacesIt(const Graph& graph, Node n1, Node n2) : _graph(
-        &graph), _n1(n1), _n2(n2), _i1(), _i2(){
+        &graph), _n1(n1), _n2(n2), _i2(), _f1(){
+        Arc _i1;
         _graph->firstOut(_i1,_n1);
+        while (_i1 != INVALID) {
+          _f1.insert(_graph->leftFace(_i1));
+          _graph->nextOut(_i1);
+        }
         _graph->firstOut(_i2,_n2);
-        while (_i1 != INVALID && _graph->leftFace(_i1) != _graph->leftFace(_i2))
-        {
+        _graph->firstOut(_i2,_n2);
+        while (_i2 != INVALID && _f1.count(_graph->leftFace(_i2)) == 0)
           _graph->nextOut(_i2);
-          if (_i2 == INVALID) {
-            _graph->nextOut(_i1);
-            _graph->firstOut(_i2,_n2);
-          }
-        }
-        static_cast<Face&>(*this) = (_i1 != INVALID)?_graph->leftFace(_i1):
+        static_cast<Face&>(*this) = (_i2 != INVALID)?_graph->leftFace(_i2):
           INVALID;
       }
 
       CommonFacesIt& operator++() {
         _graph->nextOut(_i2);
-        if (_i2 == INVALID) {
-          _graph->nextOut(_i1);
-          _graph->firstOut(_i2,_n2);
-        }
-        while (_i1 != INVALID && _graph->leftFace(_i1) != _graph->leftFace(_i2))
-        {
+        while (_i2 != INVALID && _f1.count(_graph->leftFace(_i2)) == 0)
           _graph->nextOut(_i2);
-          if (_i2 == INVALID) {
-            _graph->nextOut(_i1);
-            _graph->firstOut(_i2,_n2);
-          }
-        }
-        static_cast<Face&>(*this) = (_i1 != INVALID)?_graph->leftFace(_i1):
+        static_cast<Face&>(*this) = (_i2 != INVALID)?_graph->leftFace(_i2):
           INVALID;
         return *this;
       }
@@ -1333,7 +1325,8 @@
   class CommonNodesIt : public Node {
       const Graph* _graph;
       const Face _f1, _f2;
-      Arc _i1, _i2;
+      Arc _i2;
+      std::set<Node> _ns;
     public:
 
       CommonNodesIt() {}
@@ -1341,36 +1334,26 @@
       CommonNodesIt(Invalid i) : Face(i) { }
 
       explicit CommonNodesIt(const Graph& graph, Face f1, Face f2) : _graph(
-        &graph), _f1(f1), _f2(f2), _i1(), _i2(){
+        &graph), _f1(f1), _f2(f2), _i2(), _ns(){
+        Arc _i1;
         _graph->firstCwF(_i1,_f1);
+        while (_i1 != INVALID) {
+          _ns.insert(_graph->source(_i1));
+          _graph->nextCwF(_i1);
+        }
+
         _graph->firstCwF(_i2,_f2);
-        while (_i1 != INVALID && _graph->source(_i1) != _graph->source(_i2))
-        {
+        while (_i2 != INVALID && _ns.count(_graph->source(_i2)) == 0)
           _graph->nextCwF(_i2);
-          if (_i2 == INVALID) {
-            _graph->nextCwF(_i1);
-            _graph->firstCwF(_i2,_f2);
-          }
-        }
-        static_cast<Node&>(*this) = (_i1 != INVALID)?_graph->source(_i1):
+        static_cast<Node&>(*this) = (_i2 != INVALID)?_graph->source(_i2):
           INVALID;
       }
 
       CommonNodesIt& operator++() {
         _graph->nextCwF(_i2);
-        if (_i2 == INVALID) {
-          _graph->nextCwF(_i1);
-          _graph->firstCwF(_i2,_f2);
-        }
-        while (_i1 != INVALID && _graph->source(_i1) != _graph->source(_i2))
-        {
+        while (_i2 != INVALID && _ns.count(_graph->source(_i2)) == 0)
           _graph->nextCwF(_i2);
-          if (_i2 == INVALID) {
-            _graph->nextCwF(_i1);
-            _graph->firstCwF(_i2,_f2);
-          }
-        }
-        static_cast<Node&>(*this) = (_i1 != INVALID)?_graph->source(_i1):
+        static_cast<Node&>(*this) = (_i2 != INVALID)?_graph->source(_i2):
           INVALID;
         return *this;
       }
