[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Possible enhancements for Lua 5.2
- From: TNHarris <telliamed@...>
- Date: Tue, 28 Jun 2011 23:18:21 -0400
On 06/26/2011 05:29 PM, Andre Leiradella wrote:
But then I'd have to convert my switch to a series of ifs since the
pointers to the literals are computed during runtime.
I know switches are not great with sparse constant spaces such as when
using hashes (i.e. only a few tenths of used values from 2^32 possible
values) but I like the compiler doing the binary search for me (gcc
does) instead of having to figure it out myself. I'm also experimenting
hashing the hash (just shifts and xors, nothing fancy or costly) to make
the space dense enough so the switch will (hopefully) become a goto
table + one if for each case to see if it's really a match. Better than
the hard-coded binary tree...
I don't think Lua's table hash for strings is suitable for this. There
will be collisions. You should probably use a perfect hash generator
like gperf instead.