lua-users home
lua-l archive

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


On Mon, 10 May 2010 20:56:44 +0400
Arseny Vakhrushev <arseny.vakhrushev@gmail.com> wrote:

> 
> >> Could x[] be syntactic sugar for x[#x+1] ?
> >> It would make appending to lists so much nicer.
> 
> > I would worry about the hidden performance implications of this. The
> > magic # operator performs a binary search of both storage parts of the
> > table, which is an O(log N) operation.
> 
> The # operator has constant complexity I suppose. It doesn't deal with the associative part of a
> table at all. Moreover, it is not a true "length" operator for the dense part as it works that way
> only for well-managed sequences.

Can someone explain why the size (precisely: what # returns) is not stored in the background? Naively, I see this as a small cost for a great gain.

Denis
________________________________

vit esse estrany ☣

spir.wikidot.com