lua-users home
lua-l archive

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


Duck wrote:
In code in LuaSocket and COPAS, you can find a utility "set" class such as this:

...snip...

This code is very cool, and the "add at end" and "delete by removing the last element and writing it over the one you want to get rid of" is clearly more time efficient than just using set[value] = true to add and set[value] = nil to delete items.

for sets, i usually do as you mention (set[value]=true/nil), and i guess it's far more efficient than the code you quote.

the only reason it's cleverly done like that is that LuaSocket's select() fuction expects an array of sockets to wait on; and such a set is faster (nicer) than creating the array from a table's keys each time.

--
Javier