JuliaCollections / JuliaCollections/DataStructures.jl
Feature request: setfirst!(::AbstractHeap)
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 745
- Forks
- 261
- PR merge metrics
- No merged PRs in 30d
Description
Heaps are particularly useful for keeping track of the smallest (or largest) value in a collection. When being used to keep track of the N smallest values, the root is continually popped, and new elements are put in.
However, replacing the root is currently inefficient, as it entails using both pop! (causing a percolate_down!) and a push! (causing a percolate_up!). Instead, it could be implemented more efficiently like:
function setfirst!(h::AbstractArray, x, o::Ordering=Forward)
isempty(h) && return push!(h, x)
@inbounds h[1] = x
percolate_down!(h, 1, x, o)
return h
end
It would be nice if functionality like this was exported.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the AbstractHeap implementation and the existing pop!, push!, and percolate_down! entry points. Add the requested exported setfirst! functionality for replacing a heap root, including the empty-heap behavior described in the issue, then run the relevant heap tests or add coverage for both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100