lua-users home
lua-l archive

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


2014-08-14 9:59 GMT+02:00 Enrico Colombini <erix@erix.it>:
> On 14/08/2014 8.16, Dirk Laurie wrote:
>>
>> In actual applications, finding #tbl is quite often followed shortly
>> by traversing tbl from 1 to #tbl soon afterwards. E.g.
>>     for i=1.#tbl do ...
>>
>> I.e. the O(log n) length operator becomes insignificant in comparison
>> to the O(n) table traversal.
>
>
> A common case where this does not happen is when appending data:
>   t[#t + 1] = v

But in that case the built-in length operator is O(1). The very first
index it tries will work.