rust-lang / rust-lang/rust

Explain behaviour and performance of BinaryHeap for equal-ordered elements

Open
#121,713 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-collections A-docs C-enhancement T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the BinaryHeap documentation and the collections guide sections linked in the issue. Determine what guarantees, if any, apply to equally ordered elements and whether their performance has noteworthy characteristics, then document the findings and verify that both linked locations describe the behavior consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.