lua-users home
lua-l archive

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


2013/10/6 Robert Virding <robert.virding@erlang-solutions.com>:

> Wouldn't the easiest solution be for #t just to return largest integer index of the table?
> Ipairs would just continue working as before. The problem of holes would be solved,
> they are legal in the table.

If you allow #t to vary, it is expensive.

> big=1000000; tbl=setmetatable({[1]=1,[big]=big},{__len=largest})
> tbl[big]=nil

What does function `largest` look like? Possibilities:

1. Stores nothing. Traverses complete table using 'pairs' to find largest index
evey time.
2. Stores something. How does it know what you have deleted? Only one
way: complete trap-all-accesses proxy table.

Cheap alternative: Fixed-length table. Length defined once for all. Larger
indices treated as non-numeric. This may actually cover quite a large
number of actual use cases