Skip to content

BinaryHeap::retain would be useful #50671

Closed
@Yoric

Description

@Yoric

Consider a BinaryHeap in which we need to change priority of some elements. For the moment, this only way to implement this is to drain the heap and rebuild it from scratch. It would be more efficient to be able to remove only the affected elements, so as to read them.

A variant would be a

/// If `f(foo)` returns `Some(bar)`, replace `foo` with `bar`, which may have a different priority.
fn replace<F>(&mut self, f: F) where F: FnMut(&T) -> Option<T>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-acceptedCategory: A feature request that has been accepted pending implementation.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions