Index handler with list of unused: Difference between revisions
Jump to navigation
Jump to search
Line 11: | Line 11: | ||
== Methods == | == Methods == | ||
# The constructor takes <math>N</math> as an argument, creates <math>A</math> and <math>U</math>, and | # The constructor takes <math>N</math> as an argument, creates <math>A</math> and <math>U</math>, and inserts all numbers <math>1,\ldots,N</math> in <math>U</math>. | ||
# The method for inserting a new value extracts a key <math>i</math> from <math>U</math>, stores the value at <mah>A[i]</math>and returns <math>i</math>. | # The method for inserting a new value extracts a key <math>i</math> from <math>U</math>, stores the value at <mah>A[i]</math>and returns <math>i</math>. | ||
# The method to look up a value for a given key <math>i</math> returns <math>A[i]</math>. | # The method to look up a value for a given key <math>i</math> returns <math>A[i]</math>. | ||
# The method to remove a key re-inserts the key in <math>U</math>. | # The method to remove a key re-inserts the key in <math>U</math>. |
Revision as of 14:00, 20 October 2014
Abstract view
Abstract data structure: Index handler
Implementation invariant:
- There is an array [math]\displaystyle{ A }[/math] with index range [math]\displaystyle{ 1,...,N }[/math] and component type [math]\displaystyle{ \mathcal{V} }[/math].
- There is a subset [math]\displaystyle{ U }[/math] (for unused) of [math]\displaystyle{ \{1,\ldots,N\} }[/math].
- For each [math]\displaystyle{ i\in\{1,...,N_\text{max}\} }[/math] not in [math]\displaystyle{ U }[/math], [math]\displaystyle{ A[i] }[/math] is the value associated with key [math]\displaystyle{ i }[/math].
Methods
- The constructor takes [math]\displaystyle{ N }[/math] as an argument, creates [math]\displaystyle{ A }[/math] and [math]\displaystyle{ U }[/math], and inserts all numbers [math]\displaystyle{ 1,\ldots,N }[/math] in [math]\displaystyle{ U }[/math].
- The method for inserting a new value extracts a key [math]\displaystyle{ i }[/math] from [math]\displaystyle{ U }[/math], stores the value at <mah>A[i]</math>and returns [math]\displaystyle{ i }[/math].
- The method to look up a value for a given key [math]\displaystyle{ i }[/math] returns [math]\displaystyle{ A[i] }[/math].
- The method to remove a key re-inserts the key in [math]\displaystyle{ U }[/math].