[Lemon-commits] [lemon_svn] ladanyi: r1178 - hugo/trunk/doc

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:43:41 CET 2006


Author: ladanyi
Date: Thu Sep 16 21:51:28 2004
New Revision: 1178

Modified:
   hugo/trunk/doc/graphs.dox

Log:
Changed to conform to the new iterator style.

Modified: hugo/trunk/doc/graphs.dox
==============================================================================
--- hugo/trunk/doc/graphs.dox	(original)
+++ hugo/trunk/doc/graphs.dox	Thu Sep 16 21:51:28 2004
@@ -60,8 +60,6 @@
 \todo Don't we need SmartNodeSet and SmartEdgeSet?
 \todo Some cross-refs are wrong.
 
-\bug This file must be updated accordig to the new style iterators.
-
 The graph structures itself can not store data attached
 to the edges and nodes. However they all provide
 \ref maps "map classes"
@@ -97,8 +95,8 @@
   for (int i = 0; i < 3; i++)
     g.addNode();
   
-  for (NodeIt i(g); g.valid(i); g.next(i))
-    for (NodeIt j(g); g.valid(j); g.next(j))
+  for (NodeIt i(g); i!=INVALID; ++i)
+    for (NodeIt j(g); j!=INVALID; ++j)
       if (i != j) g.addEdge(i, j);
 \endcode
 
@@ -107,31 +105,18 @@
 
 \code
   std::cout << "Nodes:";
-  for (NodeIt i(g); g.valid(i); g.next(i))
+  for (NodeIt i(g); i!=INVALID; ++i)
     std::cout << " " << g.id(i);
   std::cout << std::endl;
 \endcode
 
 Here we iterate through all nodes of the graph. We use a constructor of the
-node iterator to initialize it to the first node. The next member function is
-used to step to the next node, and valid is used to check if we have passed the
-last one.
-
-\code
-  std::cout << "Nodes:";
-  NodeIt n;
-  for (g.first(n); n != INVALID; g.next(n))
-    std::cout << " " << g.id(n);
-  std::cout << std::endl;
-\endcode
-
-Here you can see an alternative way to iterate through all nodes. Here we use a
-member function of the graph to initialize the node iterator to the first node
-of the graph. Using next on the iterator pointing to the last node invalidates
-the iterator i.e. sets its value to INVALID. Checking for this value is
-equivalent to using the valid member function.
+node iterator to initialize it to the first node. The operator++ is used to
+step to the next node. Using operator++ on the iterator pointing to the last
+node invalidates the iterator i.e. sets its value to
+\ref hugo::INVALID "INVALID". This is what we exploit in the stop condition.
 
-Both of the previous code fragments print out the same:
+The previous code fragment prints out the following:
 
 \code
 Nodes: 2 1 0
@@ -139,7 +124,7 @@
 
 \code
   std::cout << "Edges:";
-  for (EdgeIt i(g); g.valid(i); g.next(i))
+  for (EdgeIt i(g); i!=INVALID; ++i)
     std::cout << " (" << g.id(g.tail(i)) << "," << g.id(g.head(i)) << ")";
   std::cout << std::endl;
 \endcode
@@ -155,12 +140,12 @@
   NodeIt first_node(g);
 
   std::cout << "Out-edges of node " << g.id(first_node) << ":";
-  for (OutEdgeIt i(g, first_node); g.valid(i); g.next(i))
+  for (OutEdgeIt i(g, first_node); i!=INVALID; ++i)
     std::cout << " (" << g.id(g.tail(i)) << "," << g.id(g.head(i)) << ")"; 
   std::cout << std::endl;
 
   std::cout << "In-edges of node " << g.id(first_node) << ":";
-  for (InEdgeIt i(g, first_node); g.valid(i); g.next(i))
+  for (InEdgeIt i(g, first_node); i!=INVALID; ++i)
     std::cout << " (" << g.id(g.tail(i)) << "," << g.id(g.head(i)) << ")"; 
   std::cout << std::endl;
 \endcode
@@ -176,11 +161,11 @@
 \code
   Graph::EdgeMap<int> m(g);
 
-  for (EdgeIt e(g); g.valid(e); g.next(e))
+  for (EdgeIt e(g); e!=INVALID; ++e)
     m.set(e, 10 - g.id(e));
   
   std::cout << "Id Edge  Value" << std::endl;
-  for (EdgeIt e(g); g.valid(e); g.next(e))
+  for (EdgeIt e(g); e!=INVALID; ++e)
     std::cout << g.id(e) << "  (" << g.id(g.tail(e)) << "," << g.id(g.head(e))
       << ") " << m[e] << std::endl;
 \endcode



More information about the Lemon-commits mailing list