31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

• Iterators are not bound to a loop, which means that the user has finer control over<br />

the iteration process. For example, the continuation condition it.valid() in the above<br />

loop could be replaced by another condition to terminate the loop once a specific<br />

node has been found (and the loop may be re-started at the same position later on).<br />

• <strong>The</strong> meaning of iteration may be modified seamlessly. For example, the filter iterators<br />

defined in sect. 13.9 restrict the iteration to a subset that is specified by an<br />

arbitrary logical condition (predicate). In other words, the nodes or edges that do<br />

not fulfill this predicate are filtered out automatically during iteration.<br />

• <strong>The</strong> functionality of iteration may be extended seamlessly. For example, the observer<br />

iterators defined in sect. 13.11 can be used to record details of the iteration. A<br />

concrete example is given in sect. 13.11: an observer iterator can be initialized such<br />

that it records the number of iterations performed by the iterator.<br />

• Iterator-based implementations of algorithms can be easily integrated into environments<br />

that are implemented according to the STL style [69], (this style has been<br />

adopted for the standard C++ library). For this purpose, sect. 13.12 define adapters,<br />

which convert graph iterators into STL iterators.<br />

13.1.2 Handles and Iterators<br />

Iterators can be used whenever the corresponding handle can be used. For example, node<br />

iterators can be used where a node is requested or edge iterators can be used where an<br />

edge is requested. For adjacency iterators, it is possible to use them whenever an edge is<br />

requested 1 .<br />

An example shows how iterators can be used as handles:<br />

NodeIt it(G);<br />

leda::node_array index(G);<br />

leda::node v;<br />

int i=0;<br />

forall_nodes(v,G) index[v]=++i;<br />

while (it.valid()) {<br />

cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!