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.

13.9 Filter Node Iterator ( FilterNodeIt )<br />

1. Definition<br />

An instance it of class FilterNodeIt< Predicate, Iter > encapsulates an object of type Iter<br />

and creates a restricted view on the set of nodes over which this internal iterator iterates.<br />

More specifically, all nodes that do not fulfill the predicate defined by Predicate are<br />

filtered out during this traversal.<br />

Class FilterEdgeIt and FilterAdjIt are defined analogously, i.e. can be used for edge<br />

iterators or adjacency iterators, respectively.<br />

Precondition: <strong>The</strong> template parameter Iter must be a node iterator, e.g. NodeIt or<br />

FilterNodeIt. Predicate must be a class which provides a method<br />

operator( ) according to the following signature: bool operator() (Iter).<br />

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

2. Creation<br />

FilterNodeIt< Predicate, Iter > it;<br />

introduces a variable it of this class, not bound to a predicate or<br />

iterator.<br />

FilterNodeIt< Predicate, Iter > it(const Predicate& pred, const Iter& base it);<br />

3. Operations<br />

introduces a variable it of this class bound to pred and base it.<br />

void<br />

it.init(const Predicate& pred, const Iter& base it)<br />

initializes it, which is bound to pred and base it afterwards.<br />

Precondition: it is not yet bound to a predicate or<br />

iterator.<br />

4. Implementation<br />

Constant overhead.<br />

5. Example<br />

Suppose each node has an own colour and we only want to see those with a specific colour,<br />

for example red (we use the <strong>LEDA</strong> colours). At first the data structures:<br />

GRAPH G;<br />

NodeIt it(G);

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

Saved successfully!

Ooh no, something went wrong!