1
1
//! A priority queue implemented with a binary heap.
2
2
//!
3
- //! Insertion and popping the largest element have `O(log n )` time complexity.
3
+ //! Insertion and popping the largest element have `O(log(n) )` time complexity.
4
4
//! Checking the largest element is `O(1)`. Converting a vector to a binary heap
5
5
//! can be done in-place, and has `O(n)` complexity. A binary heap can also be
6
- //! converted to a sorted vector in-place, allowing it to be used for an `O(n
7
- //! log n)` in-place heapsort.
6
+ //! converted to a sorted vector in-place, allowing it to be used for an `O(n * log(n))`
7
+ //! in-place heapsort.
8
8
//!
9
9
//! # Examples
10
10
//!
@@ -233,9 +233,9 @@ use super::SpecExtend;
233
233
///
234
234
/// # Time complexity
235
235
///
236
- /// | [push] | [pop] | [peek]/[peek\_mut] |
237
- /// |--------|----------|--------------------|
238
- /// | O(1)~ | O(log n ) | O(1) |
236
+ /// | [push] | [pop] | [peek]/[peek\_mut] |
237
+ /// |--------|----------- |--------------------|
238
+ /// | O(1)~ | O(log(n) ) | O(1) |
239
239
///
240
240
/// The value for `push` is an expected cost; the method documentation gives a
241
241
/// more detailed analysis.
@@ -398,7 +398,7 @@ impl<T: Ord> BinaryHeap<T> {
398
398
///
399
399
/// # Time complexity
400
400
///
401
- /// Cost is O(1) in the worst case.
401
+ /// Cost is ` O(1)` in the worst case.
402
402
#[ stable( feature = "binary_heap_peek_mut" , since = "1.12.0" ) ]
403
403
pub fn peek_mut ( & mut self ) -> Option < PeekMut < ' _ , T > > {
404
404
if self . is_empty ( ) { None } else { Some ( PeekMut { heap : self , sift : true } ) }
@@ -422,8 +422,7 @@ impl<T: Ord> BinaryHeap<T> {
422
422
///
423
423
/// # Time complexity
424
424
///
425
- /// The worst case cost of `pop` on a heap containing *n* elements is O(log
426
- /// n).
425
+ /// The worst case cost of `pop` on a heap containing *n* elements is `O(log(n))`.
427
426
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
428
427
pub fn pop ( & mut self ) -> Option < T > {
429
428
self . data . pop ( ) . map ( |mut item| {
@@ -456,15 +455,15 @@ impl<T: Ord> BinaryHeap<T> {
456
455
///
457
456
/// The expected cost of `push`, averaged over every possible ordering of
458
457
/// the elements being pushed, and over a sufficiently large number of
459
- /// pushes, is O(1). This is the most meaningful cost metric when pushing
458
+ /// pushes, is ` O(1)` . This is the most meaningful cost metric when pushing
460
459
/// elements that are *not* already in any sorted pattern.
461
460
///
462
461
/// The time complexity degrades if elements are pushed in predominantly
463
462
/// ascending order. In the worst case, elements are pushed in ascending
464
- /// sorted order and the amortized cost per push is O(log n) against a heap
463
+ /// sorted order and the amortized cost per push is ` O(log(n))` against a heap
465
464
/// containing *n* elements.
466
465
///
467
- /// The worst case cost of a *single* call to `push` is O(n). The worst case
466
+ /// The worst case cost of a *single* call to `push` is ` O(n)` . The worst case
468
467
/// occurs when capacity is exhausted and needs a resize. The resize cost
469
468
/// has been amortized in the previous figures.
470
469
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -623,7 +622,7 @@ impl<T: Ord> BinaryHeap<T> {
623
622
624
623
// `rebuild` takes O(len1 + len2) operations
625
624
// and about 2 * (len1 + len2) comparisons in the worst case
626
- // while `extend` takes O(len2 * log_2 (len1)) operations
625
+ // while `extend` takes O(len2 * log (len1)) operations
627
626
// and about 1 * len2 * log_2(len1) comparisons in the worst case,
628
627
// assuming len1 >= len2.
629
628
#[ inline]
@@ -644,7 +643,7 @@ impl<T: Ord> BinaryHeap<T> {
644
643
/// The remaining elements will be removed on drop in heap order.
645
644
///
646
645
/// Note:
647
- /// * `.drain_sorted()` is O(n lg n) ; much slower than `.drain()`.
646
+ /// * `.drain_sorted()` is ` O(n * log(n))` ; much slower than `.drain()`.
648
647
/// You should use the latter for most cases.
649
648
///
650
649
/// # Examples
@@ -729,7 +728,7 @@ impl<T> BinaryHeap<T> {
729
728
///
730
729
/// # Time complexity
731
730
///
732
- /// Cost is O(1) in the worst case.
731
+ /// Cost is ` O(1)` in the worst case.
733
732
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
734
733
pub fn peek ( & self ) -> Option < & T > {
735
734
self . data . get ( 0 )
0 commit comments