That's all well and good for two character values but obviously doesn't
scale beyond a half-word. If all the keys are already known then a
perfect hash optimized switch statement is one of the most efficient
methods I've seen.
Especially popular with compiler writers for the symbol table.
On 19/07/2013 4:40 AM, John Gilmore wrote:
I am beginning to have a suspicion that some readers at least do not
know how branch tables. C switch statements, and the like work. Here,
given a state-code of, say, 'NY', its two-byte code point, in EBCDIC
x' d5e8', is used as an offset to address a unique byte in that
table, one of bytes 0,1, 2,...,65635. A single properly framed TRTO
instruction yields the value of that target byte. There is no faster
way to do this, and this is the case even on, say, a RISC machine ,
where it must be programmed [trivially].
John McKown's suggestion that a three way branch should perhaps be
implemented as if-then-else-if-then-else-if-then-else<error sink> is
entirely correct but not interesting here. COBOL EVALUATE and its
analogues in other languages are for many-way branches.
John Gilmore, Ashland, MA 01721 - USA
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN