lua-users home
lua-l archive

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


Am 07.10.2013 03:44 schröbte Luiz Henrique de Figueiredo:
I think I prefer my approach, which had a very small incremental overhead at inserts (so was n * O(1)), but O(1) behavior for #.

But this implies a cost for all uses and users. Not everyone needs or uses #.
We prefer that cost be paid by those who need it.


The current implementation has other nice properties compared to more recent proposals, e.g.:

    local t1 = { 1, 2, 3 }
    local t2 = {}
    t2[ 3 ] = 3
    t2[ 2 ] = 2
    t2[ 1 ] = 1
    t2[ 20 ] = 1; t2[ 20 ] = nil
    assert( #t1 == #t2 )

I.e., the length only depends on the keys that are in the table *right now*, and not on the previous history of the table. That makes reusing tables much simpler.

Philipp