Skip to content

Commit 653dcaa

Browse files
authored
Rollup merge of #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 #89210
2 parents c118d8b + 956f87f commit 653dcaa

File tree

9 files changed

+26
-25
lines changed

9 files changed

+26
-25
lines changed

RELEASES.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -5170,7 +5170,7 @@ Libraries
51705170
- [Upgrade to Unicode 10.0.0][42999]
51715171
- [Reimplemented `{f32, f64}::{min, max}` in Rust instead of using CMath.][42430]
51725172
- [Skip the main thread's manual stack guard on Linux][43072]
5173-
- [Iterator::nth for `ops::{Range, RangeFrom}` is now done in O(1) time][43077]
5173+
- [Iterator::nth for `ops::{Range, RangeFrom}` is now done in *O*(1) time][43077]
51745174
- [`#[repr(align(N))]` attribute max number is now 2^31 - 1.][43097] This was
51755175
previously 2^15.
51765176
- [`{OsStr, Path}::Display` now avoids allocations where possible][42613]
@@ -8473,7 +8473,7 @@ Libraries
84738473
algorithm][s].
84748474
* [`std::io::copy` allows `?Sized` arguments][cc].
84758475
* The `Windows`, `Chunks`, and `ChunksMut` iterators over slices all
8476-
[override `count`, `nth` and `last` with an O(1)
8476+
[override `count`, `nth` and `last` with an *O*(1)
84778477
implementation][it].
84788478
* [`Default` is implemented for arrays up to `[T; 32]`][d].
84798479
* [`IntoRawFd` has been added to the Unix-specific prelude,
@@ -8995,7 +8995,7 @@ Libraries
89958995
* The `Default` implementation for `Arc` [no longer requires `Sync +
89968996
Send`][arc].
89978997
* [The `Iterator` methods `count`, `nth`, and `last` have been
8998-
overridden for slices to have O(1) performance instead of O(n)][si].
8998+
overridden for slices to have *O*(1) performance instead of *O*(*n*)][si].
89998999
* Incorrect handling of paths on Windows has been improved in both the
90009000
compiler and the standard library.
90019001
* [`AtomicPtr` gained a `Default` implementation][ap].

compiler/rustc_data_structures/src/graph/scc/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! Also computes as the resulting DAG if each SCC is replaced with a
44
//! node in the graph. This uses [Tarjan's algorithm](
55
//! https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm)
6-
//! that completes in *O(n)* time.
6+
//! that completes in *O*(*n*) time.
77
88
use crate::fx::FxHashSet;
99
use crate::graph::vec_graph::VecGraph;

compiler/rustc_data_structures/src/sorted_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod index_map;
99
pub use index_map::SortedIndexMultiMap;
1010

1111
/// `SortedMap` is a data structure with similar characteristics as BTreeMap but
12-
/// slightly different trade-offs: lookup, insertion, and removal are O(log(N))
12+
/// slightly different trade-offs: lookup, insertion, and removal are *O*(log(*n*))
1313
/// and elements can be iterated in order cheaply.
1414
///
1515
/// `SortedMap` can be faster than a `BTreeMap` for small sizes (<50) since it

library/alloc/src/collections/binary_heap.rs

+4-4
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.

library/alloc/src/vec/mod.rs

+3-3
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
///

library/core/src/iter/traits/iterator.rs

+2-1
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
///

library/std/src/collections/mod.rs

+9-9
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
//!

library/std/src/ffi/mod.rs

+2-2
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
//!

src/tools/clippy/clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ declare_clippy_lint! {
995995
declare_clippy_lint! {
996996
/// ### What it does
997997
/// Checks for use of `.iter().nth()` (and the related
998-
/// `.iter_mut().nth()`) on standard library types with O(1) element access.
998+
/// `.iter_mut().nth()`) on standard library types with *O*(1) element access.
999999
///
10001000
/// ### Why is this bad?
10011001
/// `.get()` and `.get_mut()` are more efficient and more

0 commit comments

Comments
 (0)