lua-users home
lua-l archive

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


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