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.

• Classes GRAPH and UGRAPH (sects. 11.2 and 11.5) are templates with two<br />

arguments, vtype and etype, which are reserved for a node and an edge attribute,<br />

respectively. To attach several attributes to nodes and edges, vtype and etype must<br />

be instantiated by structs whose members are the attributes.<br />

• A node array (sect. 11.8) or node map (sect. Node Maps) represents a node attribute,<br />

and analogously, edge arrays (sect. Edge Arrays) and edge maps (sect. 11.12), represent<br />

edge attributes. Several attributes can be attached to nodes and edges by<br />

instantiating several arrays or maps.<br />

Data accessors provide a uniform interface to access attributes, and the concrete organization<br />

of the attributes is hidden behind this interface. Hence, if an implementation<br />

of an algorithm does not access attributes directly, but solely in terms of data accessors,<br />

it may be applied to any organization of the attributes (in contrast, the algorithms in<br />

sect. Graph Algorithms require an organization of all attributes as node and edge arrays).<br />

Every data accessor class DA comes with a function template get:<br />

T get(DA da, Iter it);<br />

This function returns the value of the attribute managed by the data accessor da for the<br />

node or edge marked by the iterator it. Moreover, most data accessor classes also come<br />

with a function template set:<br />

void set(DA da, Iter it, T value);<br />

This function overwrites the value of the attribute managed by the data accessor da for<br />

the node or edge marked by the iterator it by value.<br />

<strong>The</strong> data accessor classes that do not provide a function template set realize attributes in<br />

such a way that a function set does not make sense or is even impossible. <strong>The</strong> constant<br />

accessor in sect. 13.14 is a concrete example: it realizes an attribute that is constant over<br />

the whole attributed set and over the whole time of the program. Hence, it does not make<br />

sense to provide a function set. Moreover, since the constant accessor class organizes its<br />

attribute in a non-materialized fashion, an overwriting function set is even impossible.<br />

Example: <strong>The</strong> following trivial algorithm may serve as an example to demonstrate the<br />

usage of data accessors and their interplay with various iterator types. <strong>The</strong> first, nested<br />

loop accesses all edges once. More specifically, the outer loop iterates over all nodes of<br />

the graph, and the inner loop iterates over all edges leaving the current node of the outer<br />

loop. Hence, for each edge, the value of the attribute managed by the data accessor da is<br />

overwritten by t. In the second loop, a linear edge iterator is used to check whether the<br />

first loop has set all values correctly.

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

Saved successfully!

Ooh no, something went wrong!