lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>From lua-l@tecgraf.puc-rio.br Wed Jul  7 21:55:53 1999
>From: Ken Rawlings <krawling@shooter.bluemarble.net>

>   Thanks, tinsert and tremove are exactly what I was looking for. Looking
>   at the documentation, though, i'm a little concerned, given the
>   lua equivalent for tinsert. That source implies that tinsert copies
>   every object at a given position(after the insert) to that position + 1,
>   so that l[3] gets copied to l[4], making room for something at l[3]. 
>   Doesn't this make tinsert a O(n) operation, and thus prohibitive for
>   dynamic additions to large data sets?

Right. They do shift everything.
However, it's done in C, not in Lua, and so it should be fast enough for
tables with say 1000 elements.
If you're really worried about this *and* have *really* large tables,
consider instead a linked list in Lua.
--lhf