On 03/18/2010 05:22 AM, Jae Hyuk Kwak wrote: > On Wed, Mar 17, 2010 at 1:04 PM, Michael Meissner > <meiss...@linux.vnet.ibm.com> wrote: >> Note, that many hash tables are computed by the modulus operation, which is >> often fairly expensive (and on machines without a hardware divide unit, >> requiring a function call). I would expect many switch statements would slow >> down if you switch to a hash operation that used modolus. > > I agree that the cost of modulation can be high, but it can be even > higher if we use a bunch of "else if". > Consider the situation that a program has about 400 cases on a single > switch statement. > > The cost of modulation will be fixed price so that there should be a > certain point that the price bis lower than else if statements.
Sure, but how often is that going to be cheaper than, for example, using a tree rather than a hash table? Andrew.