Skip to content
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

Avoid useless sift_down when std::collections::binary_heap::PeekMut is never mutably dereferenced #75974

Merged
merged 3 commits into from
Sep 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix time complexity in BinaryHeap::peek_mut docs
  • Loading branch information
SkiFire13 committed Sep 19, 2020
commit ca15e9d8a11e7c25eb85930d1da3009647c1680e
3 changes: 2 additions & 1 deletion library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Time complexity
///
/// Cost is *O*(1) in the worst case.
/// If the item is modified then the worst case time complexity is *O*(log(*n*)),
/// otherwise it's *O*(1).
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T>> {
if self.is_empty() { None } else { Some(PeekMut { heap: self, sift: false }) }
Expand Down