|
@@ -9,6 +9,16 @@ local function checkerror (msg, f, ...)
|
|
|
end
|
|
|
|
|
|
|
|
|
+local function check (t, na, nh)
|
|
|
+ if not T then return end
|
|
|
+ local a, h = T.querytab(t)
|
|
|
+ if a ~= na or h ~= nh then
|
|
|
+ print(na, nh, a, h)
|
|
|
+ assert(nil)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
local a = {}
|
|
|
|
|
|
-- make sure table has lots of space in hash part
|
|
@@ -20,6 +30,25 @@ for i=1,100 do
|
|
|
assert(#a == i)
|
|
|
end
|
|
|
|
|
|
+
|
|
|
+do -- rehash moving elements from array to hash
|
|
|
+ local a = {}
|
|
|
+ for i = 1, 100 do a[i] = i end
|
|
|
+ check(a, 128, 0)
|
|
|
+
|
|
|
+ for i = 5, 95 do a[i] = nil end
|
|
|
+ check(a, 128, 0)
|
|
|
+
|
|
|
+ a.x = 1 -- force a re-hash
|
|
|
+ check(a, 4, 8)
|
|
|
+
|
|
|
+ for i = 1, 4 do assert(a[i] == i) end
|
|
|
+ for i = 5, 95 do assert(a[i] == nil) end
|
|
|
+ for i = 96, 100 do assert(a[i] == i) end
|
|
|
+ assert(a.x == 1)
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
-- testing ipairs
|
|
|
local x = 0
|
|
|
for k,v in ipairs{10,20,30;x=12} do
|
|
@@ -65,15 +94,6 @@ local function mp2 (n) -- minimum power of 2 >= n
|
|
|
end
|
|
|
|
|
|
|
|
|
-local function check (t, na, nh)
|
|
|
- local a, h = T.querytab(t)
|
|
|
- if a ~= na or h ~= nh then
|
|
|
- print(na, nh, a, h)
|
|
|
- assert(nil)
|
|
|
- end
|
|
|
-end
|
|
|
-
|
|
|
-
|
|
|
-- testing C library sizes
|
|
|
do
|
|
|
local s = 0
|