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.

7.4 Maps ( map )<br />

1. Definition<br />

An instance M of the parameterized data type map is an injective mapping from<br />

the data type I, called the index type of M, to the set of variables of data type E, called<br />

the element type of M. I must be a pointer, item, or handle type or the type int. We use<br />

M(i) to denote the variable indexed by i. All variables are initialized to xdef , an element<br />

of E that is specified in the definition of M. A subset of I is designated as the domain of<br />

M. Elements are added to dom(M) by the subscript operator; however, the domain may<br />

also contain indices for which the access operator was never executed.<br />

Related data types are d arrays, h arrays, and dictionaries.<br />

#include < <strong>LEDA</strong>/core/map.h ><br />

2. Types<br />

map:: item<br />

map:: index type<br />

map:: element type<br />

the item type.<br />

the index type.<br />

the element type.<br />

3. Creation<br />

map M;<br />

map M(E x);<br />

map M(E x, int table sz);<br />

4. Operations<br />

creates an injective function m from I to the set of unused<br />

variables of type E, sets xdef to the default value of type E<br />

(if E has no default value then xdef is set to an unspecified<br />

element of E), and initializes M with m.<br />

creates an injective function m from I to the set of unused<br />

variables of type E, sets xdef to x, and initializes M with m.<br />

as above, but uses an initial table size of table sz instead of<br />

the default size 1.<br />

E& M[const I& i] returns the variable M(i) and adds i to dom(M).<br />

If M is a const-object then M(i) is read-only and<br />

i is not added to dom(M).<br />

bool M.defined(const I& i) returns true if i ∈ dom(M).<br />

void M.clear( ) makes M empty.<br />

void M.clear(const E& x) makes M empty and sets xdef to x.<br />

void M.set default value(const E& x)<br />

Iteration:<br />

sets xdef to x.<br />

forall(x, M) { “the entries M[i] with i ∈ dom(M) are successively assigned to x” }

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

Saved successfully!

Ooh no, something went wrong!