Index handler with list of unused
(Redirected from Index handler with unused list)
Jump to navigation
Jump to search
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
- Constructor: Takes [math]\displaystyle{ N }[/math] as an input, 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].
- Reserve index: Extracts some [math]\displaystyle{ i }[/math] from [math]\displaystyle{ U }[/math], stores [math]\displaystyle{ V }[/math] at [math]\displaystyle{ A[i] }[/math], and returns [math]\displaystyle{ i }[/math].
- Release index: Re-inserts [math]\displaystyle{ i }[/math] in [math]\displaystyle{ U }[/math].
- Get value: Returns [math]\displaystyle{ A[i] }[/math].
- Change value: Overwrites [math]\displaystyle{ A[i] }[/math] by [math]\displaystyle{ V }[/math].