Index handler: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Abstract view == '''Implementation invariant:''' # There is a positive natural number <math>N</math>. # There is an array <math>Indexes</math>...") |
|||
Line 1: | Line 1: | ||
== Abstract view == | == Abstract view == | ||
'''Representation invariant:''' | |||
# There is a positive [[Numbers#natural numbers|natural number]] <math>N</math>. | |||
# For each object, there is a specific, dynamically changing partition of <math>\{1,\ldots,N\}</math> into '''used''' and '''unused indexes'''. | |||
# For each used index, a value is stored. | |||
'''Implementation invariant:''' | '''Implementation invariant:''' | ||
# There is an array <math>Indexes</math> with index range <math>1,...,N_\text{max}</math> and integral components from <math>\{1,...,N_\text{max}\}</math>. | # There is an array <math>Indexes</math> with index range <math>1,...,N_\text{max}</math> and integral components from <math>\{1,...,N_\text{max}\}</math>. | ||
# There is a [[Sets and sequences|set]] <math>U</math> (for unused) of [[Numbers#natural numbers|natural numbers]], which has length <math>N_\text{max}-N</math> and stores pairwise different numbers from <math>\{1,...,N_\text{max}\}</math>. | # There is a [[Sets and sequences|set]] <math>U</math> (for unused) of [[Numbers#natural numbers|natural numbers]], which has length <math>N_\text{max}-N</math> and stores pairwise different numbers from <math>\{1,...,N_\text{max}\}</math>. | ||
# For each <math>i\in\{1,...,N_\text{max}\}</math> not in <math>Unused</math>: | # For each <math>i\in\{1,...,N_\text{max}\}</math> not in <math>Unused</math>: | ||
## <math>Positions[i]</math> is the position of one of the <math>N</math> heap items in <math>TheHeap</math>. As long as this heap item is stored, <math>i</math> is permanently associated with this heap item (and can hence be used to locate and access this heap item at any time). The correspondence between the heap items and these numbers <math>i</math> is one-to-one. | ## <math>Positions[i]</math> is the position of one of the <math>N</math> heap items in <math>TheHeap</math>. As long as this heap item is stored, <math>i</math> is permanently associated with this heap item (and can hence be used to locate and access this heap item at any time). The correspondence between the heap items and these numbers <math>i</math> is one-to-one. | ||
== Methods == | == Methods == |
Revision as of 08:21, 10 October 2014
Abstract view
Representation invariant:
- There is a positive natural number [math]\displaystyle{ N }[/math].
- For each object, there is a specific, dynamically changing partition of [math]\displaystyle{ \{1,\ldots,N\} }[/math] into used and unused indexes.
- For each used index, a value is stored.
Implementation invariant:
- There is an array [math]\displaystyle{ Indexes }[/math] with index range [math]\displaystyle{ 1,...,N_\text{max} }[/math] and integral components from [math]\displaystyle{ \{1,...,N_\text{max}\} }[/math].
- There is a set [math]\displaystyle{ U }[/math] (for unused) of natural numbers, which has length [math]\displaystyle{ N_\text{max}-N }[/math] and stores pairwise different numbers from [math]\displaystyle{ \{1,...,N_\text{max}\} }[/math].
- For each [math]\displaystyle{ i\in\{1,...,N_\text{max}\} }[/math] not in [math]\displaystyle{ Unused }[/math]:
- [math]\displaystyle{ Positions[i] }[/math] is the position of one of the [math]\displaystyle{ N }[/math] heap items in [math]\displaystyle{ TheHeap }[/math]. As long as this heap item is stored, [math]\displaystyle{ i }[/math] is permanently associated with this heap item (and can hence be used to locate and access this heap item at any time). The correspondence between the heap items and these numbers [math]\displaystyle{ i }[/math] is one-to-one.
Methods
- If an index is requested, [math]\displaystyle{ U\neq\emptyset }[/math] is a precondition. Then one index is extracted from [math]\displaystyle{ U }[/math] and returned.
- If an index is given back, it is inserted in [math]\displaystyle{ U }[/math].