lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 01/07/2008 17:38, Leo Razoumov wrote:
I think the manual should bee more specific of what a t[key]= nil really means
(A) t[key] element exists and is set to nil
(B) t[key] element is absent from the table/array and has not material value

That's (B), the manual and most users of this mailing list use the expression "nil value in array" as "absent from table".

Actually, from what I recall from the code of Lua, tables have a kind of dual implementation that peacefully co-exist: - For contiguous numerical keys starting at 1, Lua implements that part as a true array, with fast access of values by index. IIRC, the implementation supports some holes in the continuity. Hence the vagueness of the documentation here (depends on the kind of holes... basically, for a reliable behavior, just avoid holes!).
- For bigger numerical keys and other kind of keys, the table is implemented as a hash.

Well, actually this is documented in the ltable.c:

** Non-negative integer keys are all candidates to be kept in the array
** part. The actual size of the array is the largest `n' such that at
** least half the slots between 0 and n are in use.

But it is an implementation detail, users shouldn't rely on it...

Philippe Lhoste
--  (near) Paris -- France
--  --  --  --  --  --  --  --  --  --  --  --  --  --