[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Deleting all elements from a table
- From: "Leo Razoumov" <slonik.az@...>
- Date: Thu, 14 Sep 2006 12:34:23 -0400
On 9/13/06, Roberto Ierusalimschy <email@example.com> wrote:
> local k= next(t)
> while k ~= nil do
> t[k]= nil
> k= next(t)
It may be worth remembering that the above loop is quadratic in time.
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??