lua-users home
lua-l archive

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


On 9/13/06, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> local k= next(t)
> while k ~= nil do
>  t[k]= nil
>  k= next(t)
> end

It may be worth remembering that the above loop is quadratic in time.

-- Roberto


Roberto,
I am sorry but I think this loop is linear in time (number of elements
in table 't').
next(t) is equivalent to next(t,nil) and returns the head element of
the table in constant time. The loop itself is linear in time. Overall
it is O(t) -- linear time.
Am I missing something??

--Leo--