Perfect hashing for string switch

bearophile bearophileHUGS at lycos.com
Wed Jan 27 05:17:39 PST 2010


BCS:
> Have you compared it to a decisition tree or lex style state mechine?

I have now implemented that too, it was not an immediate thing to do (I have removed the versions 2 to 5 to reduce code size on codepad):
http://codepad.org/zOmPeE13

The results are good:
Timings, ldc, seconds:
  test1: 4.48 // normal string switch
  test2: 2.98 // perfect hash
  test3: 2.09
  test4: 2.07
  test5: 5.44 // AA. Tango AA opIn_r is bug-slow
  test6: 1.18 // new result

I hope this is enough.
I have created that large finite state machine in D with a Python program :-)

Bye,
bearophile



More information about the Digitalmars-d mailing list