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.
4
- //! Checking the largest element is `O (1)` . Converting a vector to a binary heap
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 * log(n))`
3
+ //! Insertion and popping the largest element have *O* (log(*n*)) time complexity.
4
+ //! Checking the largest element is *O* (1). Converting a vector to a binary heap
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* \ * log(*n*))
7
7
//! in-place heapsort.
8
8
//!
9
9
//! # Examples
@@ -235,7 +235,7 @@ use super::SpecExtend;
235
235
///
236
236
/// | [push] | [pop] | [peek]/[peek\_mut] |
237
237
/// |--------|-----------|--------------------|
238
- /// | O(1)~ | O (log(n )) | O (1) |
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,7 +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(n))` .
425
+ /// The worst case cost of `pop` on a heap containing *n* elements is *O* (log(*n*)) .
426
426
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
427
427
pub fn pop ( & mut self ) -> Option < T > {
428
428
self . data . pop ( ) . map ( |mut item| {
@@ -455,15 +455,15 @@ impl<T: Ord> BinaryHeap<T> {
455
455
///
456
456
/// The expected cost of `push`, averaged over every possible ordering of
457
457
/// the elements being pushed, and over a sufficiently large number of
458
- /// 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
459
459
/// elements that are *not* already in any sorted pattern.
460
460
///
461
461
/// The time complexity degrades if elements are pushed in predominantly
462
462
/// ascending order. In the worst case, elements are pushed in ascending
463
- /// 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
464
464
/// containing *n* elements.
465
465
///
466
- /// 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
467
467
/// occurs when capacity is exhausted and needs a resize. The resize cost
468
468
/// has been amortized in the previous figures.
469
469
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -643,7 +643,7 @@ impl<T: Ord> BinaryHeap<T> {
643
643
/// The remaining elements will be removed on drop in heap order.
644
644
///
645
645
/// Note:
646
- /// * `.drain_sorted()` is `O(n * log(n))` ; much slower than `.drain()`.
646
+ /// * `.drain_sorted()` is *O*(*n* \ * log(*n*)) ; much slower than `.drain()`.
647
647
/// You should use the latter for most cases.
648
648
///
649
649
/// # Examples
@@ -756,7 +756,7 @@ impl<T> BinaryHeap<T> {
756
756
///
757
757
/// # Time complexity
758
758
///
759
- /// Cost is `O (1)` in the worst case.
759
+ /// Cost is *O* (1) in the worst case.
760
760
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
761
761
pub fn peek ( & self ) -> Option < & T > {
762
762
self . data . get ( 0 )
@@ -1312,7 +1312,7 @@ unsafe impl<T: Ord> TrustedLen for DrainSorted<'_, T> {}
1312
1312
impl < T : Ord > From < Vec < T > > for BinaryHeap < T > {
1313
1313
/// Converts a `Vec<T>` into a `BinaryHeap<T>`.
1314
1314
///
1315
- /// This conversion happens in-place, and has `O(n)` time complexity.
1315
+ /// This conversion happens in-place, and has *O*(*n*) time complexity.
1316
1316
fn from ( vec : Vec < T > ) -> BinaryHeap < T > {
1317
1317
let mut heap = BinaryHeap { data : vec } ;
1318
1318
heap. rebuild ( ) ;
0 commit comments