[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Sorting table compares with nil
- From: Rici Lake <lua@...>
- Date: Mon, 2 Jul 2007 18:04:43 -0500
On 2-Jul-07, at 5:35 PM, Gavin Kistner wrote:
Given the presence of 00F08860 getting passed to my comparison
function,
it seems that table.sort tries to sort all the integer keys in the
array, instead of the convential "from 1 up to the first nil" view of
an
array.
table.sort(t) sorts elements with keys from 1 to #t. #t is not
uniquely determined for tables whose integer keys are sparse.
Is this behavior expected? Do I need to wipe out all the subsequent
values, instead of just inserting a nil marker?
Yes. Maybe you should just construct a new table instead of trying to
recycle the old one. For example, as far as I can see, your current
code leaves old reverse-lookup elements in place, which could create
something which looks a lot like a memory leak.
Do I need to also worry about the non-integer keys in the table? (The
reverse-lookup elements pushed in at the end.)
Not as far as table.sort goes.