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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

We would have to write something like this:<br />

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

if (G[it.get_node()]==red) do_something(it);<br />

++it;<br />

}<br />

With the filter wrapper class we can add the test if the node is red to the behaviour of<br />

the iterator.<br />

struct RedPred {<br />

bool operator() (const NodeIt& it) const {<br />

return G[it.get_node()]==red; }<br />

} redpred;<br />

FilterNodeIt red_it(redpred,it);<br />

This simplifies the loop to the following:<br />

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

do_something(red_it);<br />

++red_it; }<br />

All ingredients of the comparison are hard-wired in struct RedPred: the type of the compared<br />

values (color), the comparison value (red) and the binary comparison (equality).<br />

<strong>The</strong> following class CompPred renders these three choices flexible.<br />

13.10 Comparison Predicate ( CompPred )<br />

1. Definition<br />

An instance cp of class CompPred is a predicate comparator that produces<br />

boolean values with the given compare function and the attribute associated with<br />

an iterator.<br />

#include < <strong>LEDA</strong>/graph/graph iterator.h >

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

Saved successfully!

Ooh no, something went wrong!