[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Utility functions to manage sets
- From: Javier Guerra Giraldez <javier@...>
- Date: Mon, 02 Jul 2007 20:18:44 -0500
In code in LuaSocket and COPAS, you can find a utility "set" class such
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.