Control table: Difference between revisions

Content deleted Content added
Table structure: Edit for brevity
Table structure: Remove fluff; don't need to tell folks what both dec and hex are
Line 24:
|+ Table that map each ASCII value (A,D,M,S) to a subroutine index (1,4,3,2) via a one-dimensional array<br/>{{nobold|(omitted values are shown as '...')}}
|- style="vertical-align:bottom;"
! [[index (ASCII]]!! Decimal !! [[Hexadecimal]]) !! Array
|-
| [[Null character|null]] || &nbsp;0 || 00... ||style="background:lightblue;"| 00
|-
| ... || ... |{{hex2dec|41}} ...(A) ||style="background:lightblue;"| 00'''01'''
|-
| [[@]] || {{hex2dec|40}} || 40... ||style="background:lightblue;"| 00
|-
|A || {{hex2dec|4144}} || 41(D) ||style="background:lightblue;"| '''0104'''
|-
| ... || ...|| ... ||style="background:lightblue;"| 00
|-
|D || {{hex2dec|444D}} || 44(M) ||style="background:lightblue;"| '''0403'''
|-
| ... || ... || ... ||style="background:lightblue;"| 00
|-
|M || {{hex2dec|4D53}} || 4D(S) ||style="background:lightblue;"| '''0302'''
|-
| ... || ... || ... ||style="background:lightblue;"| 00
|-
|S || {{hex2dec|53}} || 53 ||style="background:lightblue;"| '''02'''
|}
In perhaps its simplest implementation, a control table may sometimes be a one-dimensional table for ''directly'' translating a [[raw data]] value to a corresponding subroutine [[offset (computer science)|offset]], [[array data structure|index]] or [[pointer (computer programming)|pointer]] using the raw data value either directly as the index to the array, or by performing some basic arithmetic on the data beforehand. This can be achieved in [[constant time]] (without a [[linear search]] or [[binary search]] using a typical [[lookup table]] on an [[associative array]]). In most [[computer architecture|architecture]]s, this can be accomplished in two or three [[machine instruction]]s – without any comparisons or loops. The technique is known as a "[[trivial hash function]]" or, when used specifically for branch tables, "[[double dispatch]]".