Index handler

From Algowiki
Revision as of 14:14, 20 October 2014 by Weihe (talk | contribs)
Jump to navigation Jump to search

Representation invariant

This abstract data structure is generic and parameterized by some value type [math]\displaystyle{ \mathcal{V} }[/math]. An object of an implementation of this abstract data structure is repesented by:

  1. A positive integral number [math]\displaystyle{ N }[/math].
  2. A subset [math]\displaystyle{ I }[/math] of [math]\displaystyle{ \{1,\ldots,N\} }[/math], the currently used indexes.
  3. A mapping [math]\displaystyle{ I\rightarrow\mathcal{V} }[/math].

Remark: This abstact data structure may be viewed as a specific, quite restricted type of map.

Method

Name: reserve index

Argument: A value [math]\displaystyle{ V\in\mathcal{V} }[/math].

Precondition: [math]\displaystyle{ |I|\lt N }[/math].

Return value: One of the indexes not in [math]\displaystyle{ I }[/math].

Postcondition: The returned index is inserted in [math]\displaystyle{ I }[/math] and associated with [math]\displaystyle{ V }[/math].

Method

Name: release index

Argument: An integral number [math]\displaystyle{ i }[/math].

Precondition: [math]\displaystyle{ i\in I }[/math].

Postcondition: [math]\displaystyle{ i }[/math] is extracted from [math]\displaystyle{ i }[/math] and the associated value removed.

Method

'Name: get value

Argument: An integral number [math]\displaystyle{ i }[/math].

Precondition: [math]\displaystyle{ i\in I }[/math].

Return value: The value currently associated with [math]\displaystyle{ i }[/math].,

Method

Name: change value

Argument: An integral number [math]\displaystyle{ i }[/math] and a value [math]\displaystyle{ V\in\mathcal{V} }[/math].

Precondition: [math]\displaystyle{ i\in I }[/math].

Postcondition: The value currently associated with [math]\displaystyle{ i }[/math] is overwritten by [math]\displaystyle{ V }[/math].