Skip to content

Conversation

Drvi
Copy link

@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
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.

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.

2 participants