next up previous contents index
Next: Maps ( map ) Up: Dictionaries Previous: Dictionary Arrays with Implementation   Contents   Index


Hashing Arrays ( h_array )

Definition

An instance A of the parameterized data type h_array<I,E> (hashing array) is an injective mapping from a hashed data type I (cf. section Hashed Types), called the index type of A, to the set of variables of arbitrary type E, called the element type of A. We use A(i) to denote the variable indexed by i and we use dom(A) to denote the set of ``used indices''. This set is empty at the time of creation and is modified by array accesses. Each hashing array has an associated default value xdef. The variable A(i) has value xdef for all i $ \notin$dom(A).

Related data types are d_arrays, maps, and dictionaries.

#include < LEDA/h _array.h >

Creation

h_array<I,E> A creates an injective function a from I to the set of unused variables of type E, sets xdef to the default value of type E (if E has no default value then xdef stays undefined) and dom(A) to the empty set, and initializes A with a.

h_array<I,E> A(E x) creates an injective function a from I to the set of unused variables of type E, sets xdef to x and dom(A) to the empty set, and initializes A with a.

h_array<I,E> A(E x, int table_sz) as above, but uses an initial table size of table_sz instead of the default size 1.

Operations

E& A[I i] returns the variable A(i).

bool A.defined(I i) returns true if i $ \in$ dom(A) and false otherwise.

void A.undefine(I i) removes i from dom(A) and sets A(i) to xdef.

void A.clear() makes dom(A) empty.

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


Iteration

forall_defined(i, A) { ``the elements from dom(A) are successively assigned to i'' }

forall(x, A) { ``for all i $ \in$ dom(A) the entries A[i] are successively assigned to x'' }

Implementation

Hashing arrays are implemented by hashing with chaining. Access operations take expected time O(1). In many cases, hashing arrays are more efficient than dictionary arrays (cf. Dictionary Arrays).


next up previous contents index
Next: Maps ( map ) Up: Dictionaries Previous: Dictionary Arrays with Implementation   Contents   Index
LEDA research project
2000-02-09