lua-users home
lua-l archive

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

> 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.