Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heap is broken with objects #23

Open
fbernier opened this issue May 1, 2014 · 4 comments · May be fixed by #53
Open

Heap is broken with objects #23

fbernier opened this issue May 1, 2014 · 4 comments · May be fixed by #53

Comments

@fbernier
Copy link

fbernier commented May 1, 2014

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

@dirkholzapfel
Copy link

any updates on this issue?

@fbernier
Copy link
Author

fbernier commented Aug 5, 2015

@dirkholzapfel I ended up using https://github.com/rubyworks/pqueue instead

@shiduanguang
Copy link

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

@shiduanguang
Copy link

This Heap is slower very much than Ruby's built in Array sorting. I'm using Ruby 2.2.4.

bcc32 added a commit to bcc32/algorithms that referenced this issue Dec 30, 2023
@bcc32 bcc32 linked a pull request Dec 30, 2023 that will close this issue
bcc32 added a commit to bcc32/algorithms that referenced this issue Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants