[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: ordered numeric set vs. tinsert()
- From: "Fabio Reis Cecin" <frcecin@...>
- Date: Fri, 31 Jan 2003 18:46:36 -0200
Thanks! but my problem is just that - performance :-)
I can't use foreachi(). For instance, this takes about half a minute to
execute here:
function nop(i,v) end
set = { }
set[9999999] = 1
foreachi (set, nop)
- Fabio
On 31 Jan 2003, at 21:09, Peter Prade wrote:
> Here is what i do (Lua 4 code):
>
> -- foreach replacement that sorts the indizes
> function foreachsorted(t, f)
> local indizes = tkeys(t)
> sort(indizes)
> foreachi(indizes, function(_, i) %f(i, %t[i]) end)
> end
>
> -- returns all keys of the given table as values (in an array-table)
> function tkeys(t)
> local n=1
> local ret={}
> for i,v in t do
> ret[n] = i
> n = n + 1
> end
> return ret
> end
>
> as you can see, i don't care about performance. if you do, you might want to
> try something else ;-)
>
> Cheers,
> Peter
--
[]'s
Fábio R. Cecin
frcecin@terra.com.br