lua-users home
lua-l archive

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

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.

- --
┌─── ───── ─────
│ "Sufficiently advanced incompetence is indistinguishable from
│ malice." -- Vernon Schryver
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla -