[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Extract a list of keys from table
- From: "Alexander Gladysh" <agladysh@...>
- Date: Sat, 19 Jul 2008 01:03:54 +0400
On Sat, Jul 19, 2008 at 12:12 AM, Alexander Gladysh <agladysh@gmail.com> wrote:
> Methods:
>
> * noop -- function() end
> * c -- Implementation in plain C (module built with -O2 by Apple's GCC 4.0.1)
> * generated -- Pregenerated version (return t[a1], t[a2]... t[aN])
> * unpack -- table creation
> * recursive -- Recursive call version
By the way. The 'generated' method is based on this function:
local generate_extractor = function(n)
assert(type(n) == "number")
local a, r = {}, {}
for i = 1, n do
a[i], r[i] = 'a'..i, 't[a'..i..']'
end
return assert(
loadstring(
[[return function(t,]]..table_concat(a, ",")..[[)return
]]..table_concat(r, ",").."end",
"extract_keys_"..n
)
)()
end
Is it possible somehow to implement it without loadstring, but via
means of return function(t, ...) <...> end?
Also, since we have benchmark up and running, does anyone have any
other however crazy idea on the alternative implementation of
extract_keys?
Alexander.