Skip to content

Mutable access to the highest-priority element in a BinaryHeap #1626

@moosingin3space

Description

@moosingin3space

The current implementation of BinaryHeap makes it difficult to write efficient I/O schedulers. I propose the addition of a function to BinaryHeap (inexact form):

fn peek_mut<F: FnOnce(Option<&mut T>)>(&mut self, func: F) {
    func(self.data.get(0));
    self.sift_down_to_bottom(0);
}

that would allow the caller to mutate the highest-priority element in the heap, then restore the heap property after the closure completes.

This functionality makes it much easier to build efficient priority-queue-based schedulers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions