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.3 Hashing Arrays ( h array )<br />

1. Definition<br />

An instance A of the parameterized data type h array (hashing array) is an injective<br />

mapping from a hashed data type I , called the index type of A, to the set of variables<br />

of arbitrary type E, called the element type of A. We use A(i) to denote the variable<br />

indexed by i and we use dom(A) to denote the set of “used indices”. This set is empty<br />

at the time of creation and is modified by array accesses. Each hashing array has an<br />

associated default value xdef . <strong>The</strong> variable A(i) has value xdef for all i ∉ dom(A). If I<br />

is a user-defined type, you have to provide a Hash function (see Section 2.3).<br />

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

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

2. Creation<br />

h array A;<br />

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

of type E, sets xdef to the default value of type E (if E has no<br />

default value then xdef stays undefined) and dom(A) to the empty<br />

set, and initializes A with a.<br />

h array A(E x);<br />

h array A(E x, int table sz);<br />

3. Operations<br />

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

of type E, sets xdef to x and dom(A) to the empty set, and<br />

initializes A with a.<br />

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

default size 1.<br />

E& A[const I& i] returns the variable A(i).<br />

bool A.defined(const I& i)<br />

void A.undefine(const I& i)<br />

void A.clear( ) makes dom(A) empty.<br />

returns true if i ∈ dom(A) and false otherwise.<br />

removes i from dom(A) and sets A(i) to xdef .<br />

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

int A.size( ) returns |dom(A)|.

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

Saved successfully!

Ooh no, something went wrong!