Skip to content

Add empty! for all Heaps #866

Open
Open
@Firionus

Description

@Firionus

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions