lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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[1] == "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.

- --
┌─── dg@cowlark.com ───── 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

iEYEARECAAYFAksLxQUACgkQf9E0noFvlzhnjQCgtiwuk0J83mP+EDChzXiKJxOP
jjoAoK82bFcmcH+9zkvTBrD8G/i67TNc
=+Vmc
-----END PGP SIGNATURE-----