Skip to content

Explain behaviour and performance of BinaryHeap for equal-ordered elements #121713

Open
@BigWingBeat

Description

@BigWingBeat

Location

Summary

The BinaryHeap collection type, unlike BTreeMap/BTreeSet, allows inserting multiple elements with an equal ordering (Ordering::Equal). However, the documentation does not explicitly mention this capability anywhere I could find.

It is unclear if there are or aren't any guarantees about how multiple equally-ordered elements are treated by methods such as peek, into_sorted_vec, etc. They could be prioritized by insertion order, or their relative order could be arbitrary but stable, or it could change between method calls.
Whatever guarantees exist should be documented, or if there aren't any, that should also be explicitly documented.

Additionally, as the entire purpose of a BinaryHeap is to store elements in a manner determined by their ordering, and given that it's already documented that it has pathological behaviour when elements are inserted in ascending order, it is not unreasonable for someone to assume that similarly pathological behaviour may exist when most or all of the elements in the heap have an equal ordering to eachother, considering that such a scenario presumably defeats most of the point of using an ordered collection over an unordered one.
If BinaryHeap has any noteworthy performance characteristics or caveats with regards to equal-ordered elements, these should be documented, or if equal-ordered elements are handled gracefully, that too should be documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.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