JuliaCollections / DataStructures.jl

Julia implementation of Data structures
https://juliacollections.github.io/DataStructures.jl/latest/
MIT License
679 stars 242 forks source link

Add empty! for all Heaps #866

Open Firionus opened 10 months ago

Firionus commented 10 months ago

I would like an empty! method for all heap types. It is currently only defined for BinaryMinMaxHeap.

Compared to using extract_all!, an empty! method would not allocate a vector, which might be important for performance oriented applications.

Maybe an implementation could look like this:

function Base.empty!(h::AbstractHeap)
    while !isempty(h)
        pop!(h)
    end
    h
end