algorithms
algorithms copied to clipboard
Heap is broken with objects
Works when the heap length is < 10 but fails with 10+
min_heap = ::Containers::Heap.new(10.times.map{Object.new}){|x, y| (x <=> y) == -1}
while val = min_heap.pop do
p val
end
RuntimeError: Couldn't delete node from stored nodes hash
any updates on this issue?
@dirkholzapfel I ended up using https://github.com/rubyworks/pqueue instead
If you let the elements not same, this err wont be raised.
min_heap = ::Containers::Heap.new(10.times.map{rand(100)}){|x, y| (x <=> y) == -1}
while val = min_heap.pop do
p val
end
But if you need elements to be same, just replace Heap with MaxHeap or MinHeap.
min_heap = ::Containers::MinHeap.new(10.times.map{Object.new}){|x, y| (x <=> y) == -1}
while val = min_heap.pop do
p val
end
This Heap is slower very much than Ruby's built in Array sorting. I'm using Ruby 2.2.4.