On Thu, Oct 24, 2013 at 12:16 AM, Luther <lutheroto@gmail.com> wrote:
The loop shows two identical sequences of keys. However, in different
runs of the program, the order of keys changes, as if the order is
completely random. I know Lua doesn't give any guarantees about the
order of keys, but I can't think of any reason why the hash table would
be constructed differently on each run. Can anyone tell me what's going
on here?
(I know C, so you can point me to the relevant source code if you think
it will help me understand.)
Luther
Because Lua's tables are hash tables. They're an unordered collection
-- they're organized according to an internal hash code for
performance, and that hashing function has some randomization involved
to help avoid pathological worst cases or maliciously-constructed
attacks.