[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ltable.c table deletion
- From: Rebel Neurofog <rebelneurofog@...>
- Date: Wed, 1 Feb 2012 00:02:35 +0300
On Wed, Feb 1, 2012 at 12:01 AM, Josh Haberman <jhaberman@gmail.com> wrote:
> >From my reading of ltable.c and lvm.c it appears that Lua does not
> remove table entries when a program does t[x] = nil, but just sets the
> entry's value to nil. Please correct me if I'm wrong.
>
> Is there a reason for this? I ask because I'm implementing my own
> hash table that uses Lua's design (chained scatter with Brent's
> variation) and discovered something that I haven't seen published
> anywhere. All chained scatter removal algorithms I've seen published
> are very complicated because they cover the case where chains have
> coalesced. For example:
> http://www.brpreiss.com/books/opus4/html/page234.html#SECTION009514000000000000000
>
> However, as I was studying this it occurred to me that Brent's
> variation (evicting a colliding element that is not in its main
> position) prevents chain coalescing, which seems that it would
> dramatically simplify the removal algorithm: you can just remove
> the target element from its own chain. This algorithm is so much
> simpler and more efficient that I was surprised that I couldn't
> find any reference to it, and I was surprised that Lua didn't
> implement it.
>
> Am I missing something?
>
> Josh
>
The behavior of next is undefined if, during the traversal, you assign
any value to a non-existent field in the table. You may however modify
existing fields. In particular, you may clear existing fields.
That's from http://www.lua.org/manual/5.2/manual.html#pdf-next