# HG changeset patch # User ladanyi # Date 1095364288 0 # Node ID fda944f15ca7803d4f01602b3a180e8846507602 # Parent 2195bc090dfe5acccdf480cac45abf094ce973b4 Changed to conform to the new iterator style. diff -r 2195bc090dfe -r fda944f15ca7 doc/graphs.dox --- a/doc/graphs.dox Thu Sep 16 19:24:15 2004 +0000 +++ b/doc/graphs.dox Thu Sep 16 19:51:28 2004 +0000 @@ -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. +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. -\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. - -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 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