-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add doc aliases for BinaryHeap pushpop and heapify implementations #84939
Conversation
BinaryHeap implements some common heap operations, like `heapify` and `pushpop` with non-standard names like `From<Vec<T>>` and `peek_mut` + `DerefMut`. This PR follows up on #28147 and adds doc aliases to `From<Vec<T>>` as _heapify_ and `peek_mut` as _pushpop_ [0]. [0]: Based on its name in Python - https://docs.python.org/3/library/heapq.html#heapq.heappushpop
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
It isn't obvious to me if (As a side note, how prevalent is the terminology used by Python? |
if let Some(mut peek) = heap.peek_mut() {
let popped = std::mem::replace(&mut peek, pushed);
Some(popped)
} else {
None
} I do agree that a more ergonomic pushpop would be
This was also the terminology used in the tracking issue linked in this PR description. |
The difference is specifically in the order of the |
I've updated the above code to reflect that pushpop can be implemented with This is the implementation of def heappushpop(heap, item):
"""Fast version of a heappush followed by a heappop."""
if heap and heap[0] < item:
item, heap[0] = heap[0], item
_siftup(heap, 0)
return item |
My motivation for adding the Even if the documentation of |
@kennytm is there a desire to move forward with this PR? |
I'm going to mark this as S-blocked on rust-lang/libs-team#18, cc @m-ou-se |
We have a policy now for doc aliases, so this is no longer blocked: https://std-dev-guide.rust-lang.org/documentation/doc-alias-policy.html However, these aliases do not fit within that policy, so I'm closing this PR. |
BinaryHeap implements some common heap operations, like
heapify
andpushpop
with non-standard names likeFrom<Vec<T>>
andpeek_mut
+DerefMut
.This PR follows up on #28147 and adds doc aliases to
From<Vec<T>>
as heapify andpeek_mut
as pushpop [0].[0]: Based on its name in Python - https://docs.python.org/3/library/heapq.html#heapq.heappushpop
Docs Screenshots