Skip to content

Commit df02aaf

Browse files
authored
Rollup merge of rust-lang#89216 - r00ster91:bigo, r=dtolnay
Consistent big O notation This makes the big O time complexity notation in places with markdown support more consistent. Inspired by rust-lang#89210
2 parents 2deedf7 + 3dc873f commit df02aaf

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

alloc/src/collections/binary_heap.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! Insertion and popping the largest element have *O*(log(*n*)) time complexity.
44
//! Checking the largest element is *O*(1). Converting a vector to a binary heap
55
//! 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*))
6+
//! converted to a sorted vector in-place, allowing it to be used for an *O*(*n* * log(*n*))
77
//! in-place heapsort.
88
//!
99
//! # Examples
@@ -243,9 +243,9 @@ use super::SpecExtend;
243243
///
244244
/// # Time complexity
245245
///
246-
/// | [push] | [pop] | [peek]/[peek\_mut] |
247-
/// |--------|-----------|--------------------|
248-
/// | O(1)~ | *O*(log(*n*)) | *O*(1) |
246+
/// | [push] | [pop] | [peek]/[peek\_mut] |
247+
/// |---------|---------------|--------------------|
248+
/// | *O*(1)~ | *O*(log(*n*)) | *O*(1) |
249249
///
250250
/// The value for `push` is an expected cost; the method documentation gives a
251251
/// more detailed analysis.

alloc/src/vec/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! A contiguous growable array type with heap-allocated contents, written
22
//! `Vec<T>`.
33
//!
4-
//! Vectors have `O(1)` indexing, amortized `O(1)` push (to the end) and
5-
//! `O(1)` pop (from the end).
4+
//! Vectors have *O*(1) indexing, amortized *O*(1) push (to the end) and
5+
//! *O*(1) pop (from the end).
66
//!
77
//! Vectors ensure they never allocate more than `isize::MAX` bytes.
88
//!
@@ -1270,7 +1270,7 @@ impl<T, A: Allocator> Vec<T, A> {
12701270
///
12711271
/// The removed element is replaced by the last element of the vector.
12721272
///
1273-
/// This does not preserve ordering, but is O(1).
1273+
/// This does not preserve ordering, but is *O*(1).
12741274
///
12751275
/// # Panics
12761276
///

core/src/iter/traits/iterator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,10 +1795,11 @@ pub trait Iterator {
17951795
/// The relative order of partitioned items is not maintained.
17961796
///
17971797
/// # Current implementation
1798+
///
17981799
/// Current algorithms tries finding the first element for which the predicate evaluates
17991800
/// to false, and the last element for which it evaluates to true and repeatedly swaps them.
18001801
///
1801-
/// Time Complexity: *O*(*N*)
1802+
/// Time complexity: *O*(*n*)
18021803
///
18031804
/// See also [`is_partitioned()`] and [`partition()`].
18041805
///

std/src/collections/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@
9797
//!
9898
//! ## Sequences
9999
//!
100-
//! | | get(i) | insert(i) | remove(i) | append | split_off(i) |
101-
//! |----------------|----------------|-----------------|----------------|--------|----------------|
102-
//! | [`Vec`] | O(1) | O(n-i)* | O(n-i) | O(m)* | O(n-i) |
103-
//! | [`VecDeque`] | O(1) | O(min(i, n-i))* | O(min(i, n-i)) | O(m)* | O(min(i, n-i)) |
104-
//! | [`LinkedList`] | O(min(i, n-i)) | O(min(i, n-i)) | O(min(i, n-i)) | O(1) | O(min(i, n-i)) |
100+
//! | | get(i) | insert(i) | remove(i) | append | split_off(i) |
101+
//! |----------------|------------------------|-------------------------|------------------------|-----------|------------------------|
102+
//! | [`Vec`] | *O*(1) | *O*(*n*-*i*)* | *O*(*n*-*i*) | *O*(*m*)* | *O*(*n*-*i*) |
103+
//! | [`VecDeque`] | *O*(1) | *O*(min(*i*, *n*-*i*))* | *O*(min(*i*, *n*-*i*)) | *O*(*m*)* | *O*(min(*i*, *n*-*i*)) |
104+
//! | [`LinkedList`] | *O*(min(*i*, *n*-*i*)) | *O*(min(*i*, *n*-*i*)) | *O*(min(*i*, *n*-*i*)) | *O*(1) | *O*(min(*i*, *n*-*i*)) |
105105
//!
106106
//! Note that where ties occur, [`Vec`] is generally going to be faster than [`VecDeque`], and
107107
//! [`VecDeque`] is generally going to be faster than [`LinkedList`].
@@ -110,10 +110,10 @@
110110
//!
111111
//! For Sets, all operations have the cost of the equivalent Map operation.
112112
//!
113-
//! | | get | insert | remove | range | append |
114-
//! |--------------|-----------|-----------|-----------|-----------|--------|
115-
//! | [`HashMap`] | O(1)~ | O(1)~* | O(1)~ | N/A | N/A |
116-
//! | [`BTreeMap`] | O(log(n)) | O(log(n)) | O(log(n)) | O(log(n)) | O(n+m) |
113+
//! | | get | insert | remove | range | append |
114+
//! |--------------|---------------|---------------|---------------|---------------|--------------|
115+
//! | [`HashMap`] | *O*(1)~ | *O*(1)~* | *O*(1)~ | N/A | N/A |
116+
//! | [`BTreeMap`] | *O*(log(*n*)) | *O*(log(*n*)) | *O*(log(*n*)) | *O*(log(*n*)) | *O*(*n*+*m*) |
117117
//!
118118
//! # Correct and Efficient Usage of Collections
119119
//!

std/src/ffi/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
//! terminator, so the buffer length is really `len+1` characters.
4444
//! Rust strings don't have a nul terminator; their length is always
4545
//! stored and does not need to be calculated. While in Rust
46-
//! accessing a string's length is a `O(1)` operation (because the
47-
//! length is stored); in C it is an `O(length)` operation because the
46+
//! accessing a string's length is an *O*(1) operation (because the
47+
//! length is stored); in C it is an *O*(*n*) operation because the
4848
//! length needs to be computed by scanning the string for the nul
4949
//! terminator.
5050
//!

0 commit comments

Comments
 (0)