aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-11-29 17:26:20 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-11-29 17:26:20 -0300
commit002beeebe79065e03dd9f531bee367e8459e3f64 (patch)
tree5b066d30e08950c923c253ce85f702b39fbe9c31 /testes
parent9329eeac3b7035c223d7a8b63dbde1f6db371bf5 (diff)
downloadlua-002beeebe79065e03dd9f531bee367e8459e3f64.tar.gz
lua-002beeebe79065e03dd9f531bee367e8459e3f64.tar.bz2
lua-002beeebe79065e03dd9f531bee367e8459e3f64.zip
New way to keep hints for table length
Instead of using 'alimit' for keeping the size of the array and at the same time being a hint for '#t', a table now keeps these two values separate. The Table structure has a field 'asize' with the size of the array, while the length hint is kept in the array itself. That way, tables with no array part waste no space with that field. Moreover, the space for the hint may have zero cost for small arrays, if the array of tags plus the hint still fits in a single word.
Diffstat (limited to 'testes')
-rw-r--r--testes/nextvar.lua29
1 files changed, 14 insertions, 15 deletions
diff --git a/testes/nextvar.lua b/testes/nextvar.lua
index 00e509f8..d1da3cee 100644
--- a/testes/nextvar.lua
+++ b/testes/nextvar.lua
@@ -316,21 +316,6 @@ end
316local a = {} 316local a = {}
317for i=1,lim do a[i] = true; foo(i, table.unpack(a)) end 317for i=1,lim do a[i] = true; foo(i, table.unpack(a)) end
318 318
319
320-- Table length with limit smaller than maximum value at array
321local a = {}
322for i = 1,64 do a[i] = true end -- make its array size 64
323for i = 1,64 do a[i] = nil end -- erase all elements
324assert(T.querytab(a) == 64) -- array part has 64 elements
325a[32] = true; a[48] = true; -- binary search will find these ones
326a[51] = true -- binary search will miss this one
327assert(#a == 48) -- this will set the limit
328assert(select(3, T.querytab(a)) == 48) -- this is the limit now
329a[50] = true -- this will set a new limit
330assert(select(3, T.querytab(a)) == 50) -- this is the limit now
331-- but the size is larger (and still inside the array part)
332assert(#a == 51)
333
334end --] 319end --]
335 320
336 321
@@ -344,6 +329,20 @@ assert(#{1, 2, 3, nil, nil} == 3)
344print'+' 329print'+'
345 330
346 331
332do
333 local s1, s2 = math.randomseed()
334 print(string.format(
335 "testing length for some random tables (seeds 0X%x:%x)", s1, s2))
336 local N = 130
337 for i = 1, 1e3 do -- create that many random tables
338 local a = table.create(math.random(N)) -- initiate with random size
339 for j = 1, math.random(N) do -- add random number of random entries
340 a[math.random(N)] = true
341 end
342 assert(#a == 0 or a[#a] and not a[#a + 1])
343 end
344end
345
347local nofind = {} 346local nofind = {}
348 347
349a,b,c = 1,2,3 348a,b,c = 1,2,3