[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Bug report in length of simple table
- From: Peter Aronoff <telemachus@...>
- Date: Wed, 14 Sep 2016 10:23:42 -0400
Dirk Laurie <dirk.laurie@gmail.com> wrote:
> <advanced>
> This turn is caused is caused by the different ways in which the tables
> are stored (all in the "array" part in the first case, only one element
> in the "array" part in the second case). The details are quite involved
> but basically #t will not change as long as you assign to indices that
> exist (even if they have value nil)
>
> $ lua
> Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
> > t={1,nil,nil,nil,nil,nil,nil,nil,nil,10} -- indices 1 to 10 exist in the "array part"
> > #t -- there is a non-nil at the highest "array part" index
> 10
> > t[5]=5 -- assigning to an existing index does not change #t
> > #t
> 10
> > t[12]=12 -- non-existing index triggers resizing of "array part"
> > #t -- [5], [10] and [12] are now in "hash part"
> 1
> </advanced>
While we are on this *advanced* subject, I have a question: none of this
“array part” and “hash part” stuff is guaranteed, right? That is, you
shouldn’t rely on it in your code, should you? (Not that it’s immediately
clear to me how you would even rely on it, but just to be clear.)
Thanks, P
--
We have not been faced with the need to satisfy someone else's
requirements, and for this freedom we are grateful.
Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System