lua-users home
lua-l archive

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



From: [] On Behalf Of Kristofer Karlsson
Sent: 24 June 2009 15:37
To: Lua list
Subject: Re: Lua next version


Btw, if your tab:count() function uses next(t) to determine if the table is non-empty, that's still a complete table traversal if it's in fact empty, since it has to look at all array and hash positions.
(But if you're just checking t[1], that would obviously be fast enough).

My “count” works on all tables not just arrays, so yes it uses next() (actually lua_next() as it is implemented in C). t[1] would be fast, but incomplete as a table is not necessarily (or even typically) empty if that element is null. I do not get your point – when counting elements using next it must be more efficient to terminate the traversal as soon as you have your answer rather than traversing the entire table.


I disagree that Lua should have different data types for arrays and dictionaries – what about all the other data structures such as sets and lists for example? Lua should provide the tools for implementing these, not the implementations. But a true table count would be one such tool that would improve the possibilities for such implementations.