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

BoundsError in MutableBinaryHeap delete! with 3 elements #678

Closed
Firionus opened this issue Sep 14, 2020 · 0 comments
Closed

BoundsError in MutableBinaryHeap delete! with 3 elements #678

Firionus opened this issue Sep 14, 2020 · 0 comments
Labels

Comments

@Firionus
Copy link

Similar to #611, but with three elements instead of two. This one wasn't fixed in #612.

Example

running julia --check-bounds=yes and then

julia> using DataStructures

julia> x = MutableBinaryMinHeap{Int}()
MutableBinaryHeap()

julia> h1 = push!(x,1)
1

julia> h2 = push!(x,2)
2

julia> h3 = push!(x,3)
3

julia> delete!(x, h3)
ERROR: BoundsError: attempt to access 2-element Array{DataStructures.MutableBinaryHeapNode{Int64},1} at index [3]
Stacktrace:
 [1] getindex at .\array.jl:809 [inlined]
 [2] _heap_bubble_down!(::Base.Order.ForwardOrdering, ::Array{DataStructures.MutableBinaryHeapNode{Int64},1}, ::Array{Int64,1}, ::Int64) at C:\Users\Johannes\.julia\packages\DataStructures\CINja\src\heaps\mutable_binary_heap.jl:46
 [3] _binary_heap_pop!(::Base.Order.ForwardOrdering, ::Array{DataStructures.MutableBinaryHeapNode{Int64},1}, ::Array{Int64,1}, ::Int64) at C:\Users\Johannes\.julia\packages\DataStructures\CINja\src\heaps\mutable_binary_heap.jl:124
 [4] delete!(::MutableBinaryHeap{Int64,Base.Order.ForwardOrdering}, ::Int64) at C:\Users\Johannes\.julia\packages\DataStructures\CINja\src\heaps\mutable_binary_heap.jl:273
 [5] top-level scope at REPL[17]:1

Im on [864edb3b] DataStructures v0.18.5. Same bug also appeared on [864edb3b] DataStructures v0.17.14, so it's not a regression.

Running the same code without --check-bounds=yes works as expected:

julia> using DataStructures

julia> x = MutableBinaryMinHeap{Int}()
MutableBinaryHeap()

julia> h1 = push!(x,1)
1

julia> h2 = push!(x,2)
2

julia> h3 = push!(x,3)#
3

julia> x
MutableBinaryHeap(1, 2, 3)

julia> delete!(x, h3)
MutableBinaryHeap(1, 2)

Note

Stumbled over it while writing a test, so tests seem to be run with bounds check. Why wouldn't this show up in the tests for DataStructures.jl?

Don't know how to fix it yet, haven't had time to look at the offending code.

@oxinabox oxinabox added the bug label Sep 14, 2020
oxinabox added a commit that referenced this issue Sep 15, 2020
Fix #678 BoundsError in MutableBinaryHeap delete! with 3 elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants