[Date Prev][Date Next][Thread Prev][Thread Next]
- 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
> 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."
http://www.mupsych.org/~rrt/ | Eschatology Generally Breeds Dire Fanaticism