[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Lua 5.2.0 (alpha) now available
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Sat, 11 Dec 2010 16:43:32 -0200
> Okay, so that brings us to the crux. The question is whether sparse
> tables are an implementation Artifact or a Feature.
There is only one data structuring mechanism in Lua, the table, which is
an associative array. By definition, this is a sparse data structure, in
the sense that only actual pairs are represented; there are no holes in
a Lua table, only absent keys.
The standard Lua implementation uses an optimized representation that
represents some pairs having integer keys with just the value, the
key being implicit. When used well, this allows the representations
of arrays that consume less memory than one that represents all pairs
explicitly. Note, however, that even if a table is used as an array,
there is no guarantee that all key will remain implicit. This seems to
be a point that is frequently missed.
Finally, the optimized representation is transparent to programmers and
even to the rest of the Lua core.