[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pairs(t, skey) and ipairs(t, skey)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sun, 6 Oct 2013 08:45:04 +0200
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
- References:
- Re: pairs(t, skey) and ipairs(t, skey), Roberto Ierusalimschy
- Re: pairs(t, skey) and ipairs(t, skey), Leo Razoumov
- Re: pairs(t, skey) and ipairs(t, skey), Luiz Henrique de Figueiredo
- Re: pairs(t, skey) and ipairs(t, skey), Tim Hill
- Re: pairs(t, skey) and ipairs(t, skey), Luiz Henrique de Figueiredo
- RE: pairs(t, skey) and ipairs(t, skey), Schmidt, Phil
- Re: pairs(t, skey) and ipairs(t, skey), Javier Guerra Giraldez
- Re: pairs(t, skey) and ipairs(t, skey), Robert Virding