Skip to content

Binary heap constructor - #564

Closed
hiemstar wants to merge 2 commits into
JuliaCollections:masterfrom
hiemstar:binary_heap_constructor
Closed

hiemstar wants to merge 2 commits into
JuliaCollections:masterfrom
hiemstar:binary_heap_constructor

Conversation

@hiemstar

Copy link
Copy Markdown

Modified internal constructor of BinaryHeap:

function BinaryHeap{T,Comp}(::Comp, xs::AbstractVector{T}) where {T,Comp}
    valtree = _make_binary_heap(Comp(), T, xs)
    new{T,Comp}(Comp(), valtree)
end

to

function BinaryHeap{T,Comp}(comp::Comp, xs::AbstractVector{T}) where {T,Comp}
    valtree = _make_binary_heap(comp, T, xs)
    new{T,Comp}(comp, valtree)
end

This makes it possible to heapify an array based on data not stored in the array itself.

@codecov

codecov Bot commented Dec 24, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #564 into master will decrease coverage by 0.04%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #564      +/-   ##
==========================================
- Coverage   87.82%   87.78%   -0.05%     
==========================================
  Files          32       32              
  Lines        2087     2088       +1     
==========================================
  Hits         1833     1833              
- Misses        254      255       +1
Impacted Files Coverage Δ
src/heaps/binary_heap.jl 97.72% <66.66%> (-2.28%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 685d33d...0a99afd. Read the comment docs.

@oxinabox

Copy link
Copy Markdown
Member

@dillondaudert can you review?

@dillondaudert

Copy link
Copy Markdown
Contributor

Hi, thanks for the PR. Could you clarify with examples what exactly this change allows?

You'll also want to make sure that all the heaps (including the MinMax heap) follow the same API and have unit tests to cover any changed functionality.

@jakobnissen

Copy link
Copy Markdown

@hiemstar It appears to me that what this PR does is allows you to instantiate a BinaryMinHeap that has the max heap property and vice versa. To me, this would break the expected behaviour of the heap. Can you clarify what you intend this PR to do?

@nsajko

nsajko commented Oct 9, 2026

Copy link
Copy Markdown
Member

The change proposed here is merged with PR #673.

@nsajko nsajko closed this Oct 9, 2026
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 this pull request may close these issues.

5 participants