lua-users home
lua-l archive

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


On 27/03/2008, at 9:49 AM, Javier Guerra wrote:
On Wed, Mar 26, 2008 at 1:43 PM, Geoff Leyland
<geoff_leyland@fastmail.fm> wrote:
 Here's the code with the tests.  No guarantees it works :)

a simpleminded optimization (reduce the use of #self) gains a 20% speedup:

Nice! I didn't know # was slow, so thanks a bunch for pointing that out Javier.

ok, i wrote the 'h:reheapify()' function:

Thanks. For the stuff I actually use this for it's small cycles so I guess the push is better, but it's definitely worth adding.

but also noted that your speed test of the sort()ed queue just inserts
numbers in the queue, while the heap uses a {key,value} table for each
item... no fair!

with the overhead of creating a table per item, and using a Lua
callback for sorting... it's far,far worse than a heap, both lazy and
eager!

Good point. I added the sort test in a bit of a hurry so it was a little rough...

Cheers,
Geoff