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.7 Partially Persistent Dictionaries ( pp dictionary<br />

)<br />

1. Definition<br />

A partially persistent dictionary stores the history of a set of items (type<br />

pp dic item). Here k is a key from a linearly ordered type K, and i is an information from<br />

the data type I. An instance D of the parameterized data type pp dictionary<br />

references a version of the set in the history.<br />

An update operation may only be performed on an instance D containing the newest<br />

version v. <strong>The</strong> operation changes the set of items and creates a new version v ′ which<br />

represents the new state of the set. After the operation, D references version v ′ , and all<br />

other instances which have referenced version v remain unchanged. An access operation<br />

may be applied to any instance D. Let v denote the version referenced by D. <strong>The</strong>n the<br />

operation is carried out on the set which existed when v was created.<br />

<strong>The</strong> main advantage of a partially persistent dictionary compared to a dictionary is that<br />

copy and assignment operations use only constant time and space, because only the versions<br />

and not the whole sets are assigned.<br />

<strong>The</strong> linear order for the data type K is given by a compare object of type CMP. It must<br />

provide a function call operator which has the same syntax and semantics as a <strong>LEDA</strong><br />

compare function (see Section 2.3). <strong>The</strong> data type pp dictionary may be instantitiated<br />

without specifying the third template argument, i.e. as type pp dictionary. This<br />

data type uses the linear order which is defined by the compare function for the type K.<br />

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

2. Creation<br />

pp dictionary D(const CMP& cmp = CMP( ));<br />

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

D to an empty persistent dictionary.<br />

When the argument cmp is provided, the object is used as compare<br />

function object which defines the linear order for the data type K.<br />

3. Operations<br />

3.1 Update operations<br />

pp dic item D.insert(const K& k, const I& i)<br />

associates the information i with the key k.<br />

If there is an item in the set then it<br />

is deleted. A new item is added and<br />

returned.

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

Saved successfully!

Ooh no, something went wrong!