aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-10-28 10:54:36 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-10-28 10:54:36 -0300
commit853311e5b1c1d9fe9d006e3a4f322e9916764933 (patch)
treecae01cc75ba1fe77ebe016e6a695fb718e9c3297 /testes
parent25a2dac2bcab84d1f1ce8c49b673b4a032a29a4a (diff)
downloadlua-853311e5b1c1d9fe9d006e3a4f322e9916764933.tar.gz
lua-853311e5b1c1d9fe9d006e3a4f322e9916764933.tar.bz2
lua-853311e5b1c1d9fe9d006e3a4f322e9916764933.zip
Table rehash can resize only the hash part
If there are no integer keys outside the array part, there is no reason to resize it, saving the time to count its elements. Moreover, assignments to non-integer keys will not collapse a table created with 'table.create'.
Diffstat (limited to 'testes')
-rw-r--r--testes/nextvar.lua25
1 files changed, 22 insertions, 3 deletions
diff --git a/testes/nextvar.lua b/testes/nextvar.lua
index 5d8796f7..cee77f76 100644
--- a/testes/nextvar.lua
+++ b/testes/nextvar.lua
@@ -39,13 +39,32 @@ do -- rehash moving elements from array to hash
39 for i = 5, 95 do a[i] = nil end 39 for i = 5, 95 do a[i] = nil end
40 check(a, 128, 0) 40 check(a, 128, 0)
41 41
42 a.x = 1 -- force a re-hash 42 a[129] = 1 -- force a re-hash
43 check(a, 4, 8) 43 check(a, 4, 8) -- keys larger than 4 go to the hash part
44 44
45 for i = 1, 4 do assert(a[i] == i) end 45 for i = 1, 4 do assert(a[i] == i) end
46 for i = 5, 95 do assert(a[i] == nil) end 46 for i = 5, 95 do assert(a[i] == nil) end
47 for i = 96, 100 do assert(a[i] == i) end 47 for i = 96, 100 do assert(a[i] == i) end
48 assert(a.x == 1) 48 assert(a[129] == 1)
49end
50
51
52do -- growing hash part keeping array part
53 local a = table.create(1000)
54 check(a, 1000, 0)
55 a.x = 10
56 check(a, 1000, 1) -- array part keeps its elements
57end
58
59
60do -- "growing" length of a prebuilt table
61 local N = 100
62 local a = table.create(N)
63 for i = 1, N do
64 a[#a + 1] = true
65 assert(#a == i)
66 end
67 check(a, N, 0)
49end 68end
50 69
51 70