Skip to content

Conversation

@Drvi
Copy link
Contributor

@Drvi Drvi commented Sep 8, 2025

No description provided.

@oxinabox
Copy link
Member

oxinabox commented Sep 9, 2025

looks good from a quick glance, though i would like to look again more carefully.
Can you add this to the CHANGELOG.md?

rev = Base.ReverseOrdering(ord)

buffer = heapify(arr[1:n], rev)
buffer = heapify!(arr[1:n], rev)
Copy link
Member

Choose a reason for hiding this comment

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

This is safe since that slice is a copy. Good catch


for i = n + 1 : length(arr)
@inbounds xi = arr[i]
@inbounds for i = n + 1 : length(arr)
Copy link
Member

@oxinabox oxinabox Sep 9, 2025

Choose a reason for hiding this comment

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

Isn't this wrong? Since we do not know how arr is going to be indexed?
Or do we know?
If so it was wrong before, but it is still wrong now.

If we want this i think we need a Base.require_one_based_indexing(arr) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing this! I was sprinkling Base.require_one_based_indexing around, but then I realized that any array with non-standard indexing would not be compatible with:

# Binary heap indexing
heapleft(i::Integer) = 2i
heapright(i::Integer) = 2i + 1
heapparent(i::Integer) = div(i, 2)

So I wonder if the entire arrays-as-heaps.jl system should be documented as only compatible with one-based indexing and all these checks dropped. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I would keep the checks, and optionally document it.
the checks are more important than docs.

@Drvi Drvi requested a review from oxinabox October 21, 2025 12:37
@oxinabox
Copy link
Member

Great, can you increment this to v0.19.2 so I can tag a release after merge then this should be good to go in

@Drvi
Copy link
Contributor Author

Drvi commented Oct 24, 2025

Done! Thank you!

@oxinabox oxinabox merged commit c9961a9 into JuliaCollections:master Nov 4, 2025
12 checks passed

# Binary min-heap percolate down.
function percolate_down!(xs::AbstractArray, i::Integer, x=xs[i], o::Ordering=Forward, len::Integer=length(xs))
Base.@propagate_inbounds function percolate_down!(xs::AbstractArray, i::Integer, x, o::Ordering=Forward, len::Integer=length(xs))
Copy link
Member

Choose a reason for hiding this comment

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

This is a breaking change? It seems you made the third argument mandatory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thanks for letting me know and apologies for the mistake. I think this could be fixed by adding a default ordering argument to the method below, i.e.

- Base.@propagate_inbounds percolate_down!(xs::AbstractArray, i::Integer, o::Ordering, len::Integer=length(xs)) = percolate_down!(xs, i, xs[i], o, len)
+ Base.@propagate_inbounds percolate_down!(xs::AbstractArray, i::Integer, o::Ordering=Forward, len::Integer=length(xs)) = percolate_down!(xs, i, xs[i], o, len)

Do you agree, @oxinabox?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR to try it out: #960

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the PR above is in good shape to be merged and fix this issue. Sorry everyone, I didn't realize the method was de facto public, so I wasn't thinking about its impact on compatibility.

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.

3 participants