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.

7.6 Persistent Dictionaries ( p dictionary )<br />

1. Definition<br />

An instance D of the parameterized data type p dictionary is a set of items (type<br />

p dic item). Every item in D contains a key from the linearly ordered data type K, called<br />

the key type of D, and an information from data type I, called the information type of D.<br />

If K is a user-defined type, you have to provide a compare function (see Section 2.3).<strong>The</strong><br />

number of items in D is called the size of D. A dictionary of size zero is called empty. We<br />

use 〈k, i〉 to denote an item with key k and information i (i is said to be the information<br />

associated with key k). For each k ∈ K there is at most one item 〈k, i〉 ∈ D.<br />

<strong>The</strong> difference between dictionaries (cf. section 7.1) and persistent dictionaries lies in the<br />

fact that update operations performed on a persistent dictionary D do not change D but<br />

create and return a new dictionary D ′ . For example, D.del(k) returns the dictionary D ′<br />

containing all items it of D with key(it) ≠ k. Also, an assignment D1 = D2 does not<br />

assign a copy of D2 (with new items) to D1 but the value of D2 itself.<br />

#include < <strong>LEDA</strong>/core/p dictionary.h ><br />

2. Creation<br />

p dictionary D;<br />

creates an instance D of type p dictionary and initializes D<br />

to an empty persistent dictionary.<br />

3. Operations<br />

K D.key(p dic item it) returns the key of item it.<br />

Precondition: it ∈ D.<br />

I D.inf(p dic item it) returns the information of item it.<br />

Precondition: it ∈ D.<br />

p dic item D.locate(const K& k)<br />

returns the item with key k (nil if no such item<br />

exists in D).<br />

p dictionary D.del(const K& k) returns {x ∈ D| key(x) ≠ k}.<br />

p dictionary<br />

D.del item(p dic item it)<br />

returns {x ∈ D| x ≠ it}.<br />

p dictionary D.insert(const K& k, const I& i)<br />

returns D.del(k) ∪ {〈k, i〉}.

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

Saved successfully!

Ooh no, something went wrong!