[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua hash algorithm
- From: Terry Moore <tmm@...>
- Date: Wed, 19 Jun 2002 13:18:24 -0400
At 07:04 PM 6/19/2002 +0200, Björn De Meyer wrote:
>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
Floating points model reals, and suffer from modelling artifact (round-off errors, inexact arithmetic, etc.).
On the other hand C-language ints and strings model points in discrete spaces. Strings can be thought of as being generalized forms of integers, at least in terms of enumeration.
It would seem that it makes sense to convert floats to ints [via a portably-defined rounding rule -- not just depending on how C happens to do it on a given platform] prior to indexing.
Code that generates indices using floating point computation is subject to interesting surprises, for example:
[using Lua 4 on Win32]
Of course, it's easy to generate other examples. But perhaps folding down to ints would be better. The semantics are no more confusing, and this would allow for true linear allocation of data if the implementor desired.