-
Notifications
You must be signed in to change notification settings - Fork 30
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
Bug in PriorityQueue::remove() #28
Comments
Thank you for your bug report. The problem was in fact that the heapify operation should be only a down-heapify, but starting at the parent of the removed element. Can I use your minimal reproducer as a test case? (It will be distributed as the library under both the LGPLv3 or later and MPLv2) |
Of course, you can use it as a test case. Are you sure that the down-heapify from the parent is enough? Consider heap like this:
If you remove the number 1, it gets replaced with 17 and that should filter up two levels. Filtering down from the parent won't do it. Unless there is something I am missing that prevents a heap like this in the first place? |
You are right |
The
PriorityQueue::remove()
does not work correctly in some cases.Here is minimal reproducer:
This will pop elements in order 6, 5, 3, 4, which is clearly not correct.
I have partially debugged it and I think the
map
,heap
andqp
are updated correctly and remain consistent, but the actual algorithm for removing element from heap is not correct. It seems that theremove()
function assumes thatheapify()
will perform up-heapify or down-heapify as needed, but it in fact only performs down-heapify. So in the case when up-heapify should have happened, the "heap" vector is no longer an actual heap.The text was updated successfully, but these errors were encountered: