[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pairs(t, skey) and ipairs(t, skey)
- From: Leo Razoumov <slonik.az@...>
- Date: Thu, 3 Oct 2013 22:26:46 -0400
On 10/3/13, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
>> Lua table distinguishes sequential keys (from 1 through N) that can be
>> iterated in order using ipairs from the other keys iterated via pairs
>> that visit all the keys in a non-specified order.
>
> No, Lua makes no such distinction. ipairs does because it provides a view
> of the table as a sequence.
>
>> Another related question: How can I iterate sequential part of a table
>> from 1 through N visiting only even (or odd) elements?
>
> The crucial point in knowing N. Here is a variant of ipairs that skips
> nil entries. But it needs N.
This is precisely my point. If a table has holes there is no quick way
(faster than O(N)) to find out N. Therefore, iterating backwards
(decrementing from N down to 1) or with increments larger than 1
(e.g. over odd elements only) are not straightforward.
--Leo--
- References:
- pairs(t, skey) and ipairs(t, skey), Andrew Starks
- Re: pairs(t, skey) and ipairs(t, skey), Luiz Henrique de Figueiredo
- Re: pairs(t, skey) and ipairs(t, skey), Tom N Harris
- Re: pairs(t, skey) and ipairs(t, skey), Luiz Henrique de Figueiredo
- Re: pairs(t, skey) and ipairs(t, skey), Leo Razoumov
- Re: pairs(t, skey) and ipairs(t, skey), Roberto Ierusalimschy
- Re: pairs(t, skey) and ipairs(t, skey), Leo Razoumov
- Re: pairs(t, skey) and ipairs(t, skey), Luiz Henrique de Figueiredo