Dick Hendrickson said:
> But, if efficiency
> is important a CASE isn't great. I think most of them are implemented as
> a series of IF-THEN-ELSE jump decisions which test everything until
> they get a hit.
I don't think this is actually true.
At least for the easy cases I would expect most implementors to do a
jump table.
> Something that's pretty efficient on most machines is the computed GOTO.
There is no reason that the straight-forward transliteration of a computed
GOTO into a SELECT would not be equally efficient.
However, a jump table is not necessarily more efficient than the alternatives;
this depends on the number of cases and their density.
Other techniques which may be more efficient on particular machines in
particular situations are:
(a) linear search, as you mentioned above
[probably only effective for 2 or 3 alternatives]
(b) binary search
(c) single-level hashed jump table
[only more effective than a simple jump table if there are many
duplications or the selection space is sparse]
(d) two-level hashed jump table
Cheers,
--
...........................Malcolm Cohen, NAG Ltd., Oxford, U.K.
([log in to unmask])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|