[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua hash algorithm
- From: Björn De Meyer <bjorn.demeyer@...>
- Date: Wed, 19 Jun 2002 19:04:50 +0200
RLake@oxfam.org.uk wrote:
> 2) Hashing of numbers in Lua is problematic. It really only works for
> integers which could fit in an "int" (or "unsigned int"). There has been
> some discussion about the issue of Lua crashing on a floating point
> exception for hash keys outside of this range (for what it's worth, I
> experienced this problem on FreeBSD in various versions, although v. 4.6
> seems to be less fascist about floating point conversions.)
Well, in C, 'int' is the fastest numerical type.
On many contemprary systems, this is 32 bits wide.
This gives you more than 4 Giga keys, which,
for most practical uses, should be enough.
However, I cannot fathom why anyone would want to use
floating point keys in a hash table. Integer indexes and
string indexes make sense, but what is ` x[1.5] = "foo" '
supposed to express? What languages besides Lua allow you to do that
natively?
Anyway, to solve the problem with this (IMO) uncommon case,
I think conversion from the floating point to a string would
be the simplest solution. Perhaps Lua should do this internally?
--
"No one knows true heroes, for they speak not of their greatness." --
Daniel Remar.
Björn De Meyer
bjorn.demeyer@pandora.be