[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why do we have ipairs?
- From: Javier Guerra Giraldez <javier@...>
- Date: Tue, 10 Jun 2014 11:15:43 -0500
On Tue, Jun 10, 2014 at 11:03 AM, Thiago L. <fakedme@gmail.com> wrote:
> I thought # just used the array size? (you know, with OP_NEWTABLE you have
> hash size and array size... I thought # just returned that array size...)
no, the "array part" is an implementation detail and can be resized at
any time. #t returns an integer that can be the highest integer key
(if there are no holes), no matter what is on the array and hash
parts, or the currently allocated size of either.
a simple example:
> t = {'a','b','c','d','e','f'}
> =#t
6
> t[6]=nil -- very unlikely to cause a resize
> =#t
5
the fact that it's usually within the array part, is an optimization
that can change without affecting the definition of #t
--
Javier