Skip to content

Commit 956f87f

Browse files
committed
consistent big O notation
1 parent 197fc85 commit 956f87f

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
@@ -4985,7 +4985,7 @@ Libraries
49854985
- [Upgrade to Unicode 10.0.0][42999]
49864986
- [Reimplemented `{f32, f64}::{min, max}` in Rust instead of using CMath.][42430]
49874987
- [Skip the main thread's manual stack guard on Linux][43072]
4988-
- [Iterator::nth for `ops::{Range, RangeFrom}` is now done in O(1) time][43077]
4988+
- [Iterator::nth for `ops::{Range, RangeFrom}` is now done in *O*(1) time][43077]
49894989
- [`#[repr(align(N))]` attribute max number is now 2^31 - 1.][43097] This was
49904990
previously 2^15.
49914991
- [`{OsStr, Path}::Display` now avoids allocations where possible][42613]
@@ -8288,7 +8288,7 @@ Libraries
82888288
algorithm][s].
82898289
* [`std::io::copy` allows `?Sized` arguments][cc].
82908290
* The `Windows`, `Chunks`, and `ChunksMut` iterators over slices all
8291-
[override `count`, `nth` and `last` with an O(1)
8291+
[override `count`, `nth` and `last` with an *O*(1)
82928292
implementation][it].
82938293
* [`Default` is implemented for arrays up to `[T; 32]`][d].
82948294
* [`IntoRawFd` has been added to the Unix-specific prelude,
@@ -8810,7 +8810,7 @@ Libraries
88108810
* The `Default` implementation for `Arc` [no longer requires `Sync +
88118811
Send`][arc].
88128812
* [The `Iterator` methods `count`, `nth`, and `last` have been
8813-
overridden for slices to have O(1) performance instead of O(n)][si].
8813+
overridden for slices to have *O*(1) performance instead of *O*(*n*)][si].
88148814
* Incorrect handling of paths on Windows has been improved in both the
88158815
compiler and the standard library.
88168816
* [`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
//!
@@ -1268,7 +1268,7 @@ impl<T, A: Allocator> Vec<T, A> {
12681268
///
12691269
/// The removed element is replaced by the last element of the vector.
12701270
///
1271-
/// This does not preserve ordering, but is O(1).
1271+
/// This does not preserve ordering, but is *O*(1).
12721272
///
12731273
/// # Panics
12741274
///

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1798,10 +1798,11 @@ pub trait Iterator {
17981798
/// The relative order of partitioned items is not maintained.
17991799
///
18001800
/// # Current implementation
1801+
///
18011802
/// Current algorithms tries finding the first element for which the predicate evaluates
18021803
/// to false, and the last element for which it evaluates to true and repeatedly swaps them.
18031804
///
1804-
/// Time Complexity: *O*(*N*)
1805+
/// Time complexity: *O*(*n*)
18051806
///
18061807
/// See also [`is_partitioned()`] and [`partition()`].
18071808
///

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)