[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Improving the efficiency of next
- From: Reuben Thomas <rrt@...>
- Date: Thu, 27 Nov 2003 11:50:51 +0100 (CET)
> for k in pairs(table) do
> table[k] = nil
> end
>
> And, being a full iteration, it takes O(N). The fact
> that this code snippet is correct is one of the
> 'subtleties' of 'next' (and Lua tables in general) .
This had me foxed. The manual is clear, though:
"The behavior of next is undefined if, during the traversal, you assign
any value to a *non-existent* field in the table."
(my emphasis)
--
http://www.mupsych.org/~rrt/ | Eschatology Generally Breeds Dire Fanaticism