Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add empty! for all Heaps #866

Open
Firionus opened this issue Aug 14, 2023 · 0 comments
Open

Add empty! for all Heaps #866

Firionus opened this issue Aug 14, 2023 · 0 comments

Comments

@Firionus
Copy link

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

No branches or pull requests

1 participant