DataStructures.jl icon indicating copy to clipboard operation
DataStructures.jl copied to clipboard

Add empty! for all Heaps

Open Firionus opened this issue 2 years ago • 0 comments

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

Firionus avatar Aug 14 '23 08:08 Firionus