Lua (Ierusalimschy et al., 1996) is a well-known scripting language, popular among many programmers, most notably in the gaming industry. Remarkably, the only data-structuring mechanism in Lua, is an associative array called a table. With Lua 5.0, the reference implementation of Lua introduced hybrid tables to implement tables using both a hash table and a dynamically growing array combined together: the values associated with integer keys are stored in the array part, when suitable. All this is transparent to the user, which has a unique simple interface to handle tables. In this paper we carry out a theoretical analysis of the performance of Lua's tables, by considering various worst-case and probabilistic scenarios. In particular, we uncover some problematic situations for the simple probabilistic model where we add a new key with some fixed probability $p>\frac12$ and delete a key with probability $1-p$: the cost of performing $T$ such operations is proved to be $\Omega(T\log T)$ with high probability, instead of linear in $T$.
翻译:Lua(Ierusalimschy等人,1996年)是一种广为人知的书写语言,在许多程序员中最受欢迎,特别是在赌博行业。值得注意的是,Lua唯一的数据结构机制是称为表格的组合阵列。Lua 5.0, Lua的参考实施引入混合表格,既使用散列表格,又使用动态增长阵列组合执行表格:与整键相关的值在适合时储存在阵列部分。所有这一切都对用户来说都是透明的,用户有一个独特的简单界面来处理表格。在本文中,我们通过考虑各种最坏情况或概率假设,对卢阿表的性能进行了理论分析。特别是,我们发现了简单概率模型的一些问题,即我们添加了一个固定概率为$p ⁇ frac12美元的新键,并删除了一个概率为$-p美元的关键:执行此类操作的成本被证明是$\Omega(T\log T),概率很高,而不是0.T美元。