[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: New array type? (was: 'table' as fallback for tables)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 8 Jul 2016 09:07:48 +0200
2016-07-08 4:01 GMT+02:00 William Ahern <william@25thandclement.com>:
> I can't think of a scenario where relying on the #t+1
> guarantee alone is either more concise or more performant.
Suppose you have coroutines 'producer' and 'consumer' accessing
the same table. 'consumer' has some capricious way of choosing
an item and removing it. 'producer' has no way of knowing what
'consumer' has been doing and now needs to put a new item in.
t[#t+1] = newitem
seems to me to be unbeatably concise, and needs only O(log n)
time, but with the present Lua documentation is unsound code.
You can make it sound by sacrificing both conciseness and
performance:
local k=#t+1; while t[k] do k=k+1 end; t[k]=newitem
which may take O(n) time.
- References:
- Re: New array type? (was: 'table' as fallback for tables), Soni L.
- Re: New array type? (was: 'table' as fallback for tables), Tim Hill
- Re: New array type? (was: 'table' as fallback for tables), Coda Highland
- Re: New array type? (was: 'table' as fallback for tables), steve donovan
- Re: New array type? (was: 'table' as fallback for tables), Joseph Manning
- Re: New array type? (was: 'table' as fallback for tables), Dirk Laurie
- Re: New array type? (was: 'table' as fallback for tables), William Ahern
- Re: New array type? (was: 'table' as fallback for tables), Dirk Laurie
- Re: New array type? (was: 'table' as fallback for tables), William Ahern
- Re: New array type? (was: 'table' as fallback for tables), Ross Berteig
- Re: New array type? (was: 'table' as fallback for tables), William Ahern