Skip to content

Commit

Permalink
Merge pull request #687 from JuliaCollections/ox/misingheapconstructor
Browse files Browse the repository at this point in the history
Fix BinaryMaxHeap type alias
  • Loading branch information
oxinabox authored Oct 3, 2020
2 parents 355a7a8 + b316993 commit 353a340
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DataStructures"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.6"
version = "0.18.7"


[deps]
Expand Down
8 changes: 7 additions & 1 deletion src/heaps/binary_heap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ BinaryHeap(ordering::Base.Ordering, xs::AbstractVector{T}) where T = BinaryHeap{
BinaryHeap{T, O}() where {T, O<:Base.Ordering} = BinaryHeap{T}(O())
BinaryHeap{T, O}(xs::AbstractVector) where {T, O<:Base.Ordering} = BinaryHeap{T}(O(), xs)

const DefaultReverseOrdering = Base.ReverseOrdering{Base.ForwardOrdering}

# These constructors needed for BinaryMaxHeap, until we have https://github.com/JuliaLang/julia/pull/37822
BinaryHeap{T, DefaultReverseOrdering}() where {T} = BinaryHeap{T}(Base.Reverse)
BinaryHeap{T, DefaultReverseOrdering}(xs::AbstractVector) where {T} = BinaryHeap{T}(Base.Reverse, xs)

# Forward/reverse ordering type aliases
const BinaryMinHeap{T} = BinaryHeap{T, Base.ForwardOrdering}
const BinaryMaxHeap{T} = BinaryHeap{T, Base.ReverseOrdering}
const BinaryMaxHeap{T} = BinaryHeap{T, DefaultReverseOrdering}

BinaryMinHeap(xs::AbstractVector{T}) where T = BinaryMinHeap{T}(xs)
BinaryMaxHeap(xs::AbstractVector{T}) where T = BinaryMaxHeap{T}(xs)
Expand Down
6 changes: 6 additions & 0 deletions test/test_binheap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
@test true
end

@testset "Type Aliases" begin
# https://github.com/JuliaCollections/DataStructures.jl/issues/686
@test BinaryMaxHeap{Int}() isa BinaryMaxHeap{Int}
@test BinaryMinHeap{Int}() isa BinaryMinHeap{Int}
end

@testset "implicit conversion" begin
BinaryHeap{Float64, Base.ForwardOrdering}(vs)
BinaryMinHeap{Float64}(vs)
Expand Down

2 comments on commit 353a340

@oxinabox
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/22371

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.18.7 -m "<description of version>" 353a3405b1a1aa27ec6badb9f0132f53c0621569
git push origin v0.18.7

Please sign in to comment.