-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Implement append for BinaryHeap #32526
Copy link
Copy link
Closed
Labels
A-collectionsArea: `std::collections`Area: `std::collections`B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.In the final comment period and will be merged soon unless new substantive objections are raised.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This can be done in
O(n + m)time by appending the underlying vectors and then using the build heap algorithm in theFrom<Vec<T>>impl. Note that in some circumstances this will perform worse than repeatedlypushing (as is done inh1.extend(h2)), because the time complexity of that approach isO(m log (m + n)). In both approaches,appendshould ensure that the larger of the two heaps acts as the "destination" of the merge in order to move as few elements as possible.appendshould use a heuristic to determine which approach to take. This should be based on the sizes of the two heaps, but may also incorporate the vectors' capacities.Pseudo-code:
For now, a simple version that just
extends the smaller one into the larger one could suffice: