Skip to content

Tracking Issue for BinaryHeap::contains and BinaryHeap::remove #82001

Closed

Description

@billyrieger

Feature gate: #![feature(binary_heap_contains_remove)]

This is a tracking issue for BinaryHeap::contains and BinaryHeap::remove. These methods are missing from the BinaryHeap API and both are common operations that one would expect to have for any general-purpose container.

Previous discussion: #66724.

Public API

impl<T: Ord> BinaryHeap<T> {
    pub fn contains<Q: ?Sized>(&self, item: &Q) -> bool
    where
        T: Borrow<Q>,
        Q: PartialEq;

    pub fn remove<Q: ?Sized>(&self, item: &Q) -> Option<T>
    where
        T: Borrow<Q>,
        Q: PartialEq;
}

Steps / History

Unresolved Questions

  • What is the best way to check if an item exists in a BinaryHeap?

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-libs-api[DEPRECATED; DO NOT USE]
    on Feb 11, 2021
  2. goffrie commented on Feb 13, 2021

    @goffrie
    Contributor

    This seems like a trap in that you would usually want these to run in less-than-linear time, but they don't. e.g. the standard Dijkstra/A* applications (as in the linked discussion) definitely want sublinear access, otherwise it defeats the point.

    That being said Vec::remove also exists and takes linear time.

  3. est31 commented on Feb 17, 2021

    @est31
    Member

    @goffrie good point. Maybe the docs added by #82002 should include this as a caveat and point to using a BTreeSet if you need to do such an operation more often?

  4. m-ou-se commented on Mar 3, 2021

    @m-ou-se
    Member

    I'm closing this for now since it's not clear #82002 will be merged. We can re-open it later if needed.

    (Next time please open a tracking issue only after the addition was approved by a libs reviewer. Thanks!)

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

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions