[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: I very confuse of tabe, only the 3rd can be skiped.
- From: Nagaev Boris <bnagaev@...>
- Date: Mon, 27 Jun 2016 11:11:34 +0300
On Mon, Jun 27, 2016 at 10:23 AM, GHui <ugiwgh@qq.com> wrote:
> I very confuse of tabe, only the 3rd can be skiped.
> The test as following:
>> d={}
>> d[1]=1
>> d[2]=2
>> d[3]=3
>> d[5]=5
>> print(#d)
> 3
>
>> a={}
>> a[1]=1
>> a[3]=3
>> print(#a)
> 1
>
>> b={}
>> b[1]=1
>> b[2]=2
>> b[4]=4
>> print(#b)
> 4
>
Operator # uses binary search on raw tables [1]. It checks 1st, 2nd,
4th, 8th, etc.
[1] http://www.lua.org/source/5.3/ltable.c.html#luaH_getn
--
Best regards,
Boris Nagaev