Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement `append` for `BinaryHeap` #32526
Comments
apasel422
added
the
A-collections
label
Mar 27, 2016
This comment has been minimized.
This comment has been minimized.
|
I'd like to perform it. |
This comment has been minimized.
This comment has been minimized.
|
@xosmig Cool. Feel free to submit a PR! |
apasel422
added
the
B-unstable
label
Apr 17, 2016
alexcrichton
added
I-nominated
T-libs
labels
Jun 9, 2016
This comment has been minimized.
This comment has been minimized.
|
The libs team was unfortunately a little late on stabilizations this cycle, but we're thinking of probably doing a backport of stabilizations partway through the beta cycle. This API also follows existing conventions so should be an easy stabilization! |
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Jun 20, 2016
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this issue during triage yesterday and the decision was to stabilize. We realize that the FCP for this issue was pretty short, however, so please comment with any objections you might have! We're very willing to backport an un-stabilization for the few APIs we have this cycle. |
apasel422 commentedMar 27, 2016
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: