skewheap
is a lua library providing a self-adjusting heap. A skew heap is
notable for its ability to be quickly merged with another skew heap.
See wikipedia for details.
require 'skewheap'
a = SkewHeap.new()
a:put(10, 30, 5, 3)
a:take() -- 5
a:take() -- 10
a:take() -- 30
b = SkewHeap.new()
b:put(45, 22)
c = a:merge(b) -- c: [3, 22, 45]
-- a: [3]
-- b: [22, 45]
SOON
Returns a new, empty skew heap.
Returns the number of items in the heap.
Returns true if the heap has no items in it.
Adds a variable number of items to the heap. Returns the number of items in the heap after insertion.
Removes and returns count
items from the heap.
Returns the next item in the heap without removing it.
Combines two heaps into a new heap containing all of the items in the other heaps. The source heaps are not modified in any way.
Jeff Ober [email protected]