[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lists with nil play nice for Lua 5.2
- From: roberto@... (Roberto Ierusalimschy)
- Date: Fri, 3 Aug 2007 11:00:53 -0300
> A simple way to handle this can be to slightly modify the definition of
> the array part of a lua table :
> #t is the biggest 'n' such that all values t[1], ..., t[n] are not nil.
> The array part of a table 't' is a sub-table t[1], ..., t[#t].
>
> In this case we have a perfectly deterministic array without holes. The
> cost to do this is negligible. (The implementation can continue to store
> other keys after a hole in the array part of the table structure for
> efficiency but these are not exposed to lua as part of the array)
Can you be more specific about this implementation? I don't see how to
ensure that all t[1]...t[n] are not nil without either traversing them
all or keeping extra information and slowing down table modifications.
-- Roberto