[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: questions on tables
- From: David Given <dg@...>
- Date: Tue, 24 Nov 2009 11:35:35 +0000
-----BEGIN PGP SIGNED MESSAGE-----
> -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.
> -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.
┌─── ｄｇ＠ｃｏｗｌａｒｋ．ｃｏｍ ───── http://www.cowlark.com ─────
│ "Sufficiently advanced incompetence is indistinguishable from
│ malice." -- Vernon Schryver
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----