[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: questions on tables
- From: spir <denis.spir@...>
- Date: Tue, 24 Nov 2009 19:53:18 +0100
David Given <firstname.lastname@example.org> wrote:
> spir wrote:
> > -1- How does lua map keys to values?
> > More specifically, how does it keep the hash value constant when a key is modified:
> IIRC Lua always uses the internal object pointer as a hash, so the hash
> of a table doesn't depend on its contents. Therefore the hash value is
> always constant (and is unique for each table).
> > -2- How often does it happen to mix indexed and key-ed values in a table?
> > (I mean in real-life programming.)
> I use it quite a lot. The two main idioms are:
> - - data and attributes --- such as representing an XML element with the
> contents in the array part and the attributes in the keyed part;
> - - bidirectional --- where the array part and the keyed part contain the
> some data, but opposite ways around. So t["one"] == 1 and t == "one".
> > -3- How often does it happen to have string keys which are not kind of names?
> Sorry, don't know what you mean here.
Sure, I was not really clear. Probably I meant two things:
* Names in the sense of identifier, so that we can write subscripting t.name.
* Names in the conceptual sense, meaning that keys are names of attributes in the model.
So, my questions was whether there are common cases where strings which happen to be table keys are not names in one or the other sense. Id est mapping strings (other than names) to whatever.
> > -4- How often does it happen to have keys which are neither strings nore integers?
> Again, I do it quite a lot, usually for sets, where t[k] == true for
> values in the set.
Here I don't understand. I know the use of mapping as sets with items as pseudo-keys (to take profit of quick and constant time access). But I don't see what you mean above.
la vita e estrany