Skip to content

Commit 39f8289

Browse files
authored
Rollup merge of rust-lang#77969 - ryan-scott-dev:bigo-notation-consistency, r=m-ou-se
Doc formating consistency between slice sort and sort_unstable, and big O notation consistency Updated documentation for slice sorting methods to be consistent between stable and unstable versions, which just ended up being minor formatting differences. I also went through and updated any doc comments with big O notation to be consistent with rust-lang#74010 by italicizing them rather than having them in a code block.
2 parents 4704259 + 8446d94 commit 39f8289

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

library/alloc/src/raw_vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
259259
/// Ensures that the buffer contains at least enough space to hold `len +
260260
/// additional` elements. If it doesn't already have enough capacity, will
261261
/// reallocate enough space plus comfortable slack space to get amortized
262-
/// `O(1)` behavior. Will limit this behavior if it would needlessly cause
262+
/// *O*(1) behavior. Will limit this behavior if it would needlessly cause
263263
/// itself to panic.
264264
///
265265
/// If `len` exceeds `self.capacity()`, this may fail to actually allocate

library/alloc/src/slice.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ mod hack {
167167
impl<T> [T] {
168168
/// Sorts the slice.
169169
///
170-
/// This sort is stable (i.e., does not reorder equal elements) and `O(n * log(n))` worst-case.
170+
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*n* \* log(*n*)) worst-case.
171171
///
172172
/// When applicable, unstable sorting is preferred because it is generally faster than stable
173173
/// sorting and it doesn't allocate auxiliary memory.
@@ -202,7 +202,7 @@ impl<T> [T] {
202202

203203
/// Sorts the slice with a comparator function.
204204
///
205-
/// This sort is stable (i.e., does not reorder equal elements) and `O(n * log(n))` worst-case.
205+
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*n* \* log(*n*)) worst-case.
206206
///
207207
/// The comparator function must define a total ordering for the elements in the slice. If
208208
/// the ordering is not total, the order of the elements is unspecified. An order is a
@@ -256,8 +256,8 @@ impl<T> [T] {
256256

257257
/// Sorts the slice with a key extraction function.
258258
///
259-
/// This sort is stable (i.e., does not reorder equal elements) and `O(m * n * log(n))`
260-
/// worst-case, where the key function is `O(m)`.
259+
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*m* \* *n* \* log(*n*))
260+
/// worst-case, where the key function is *O*(*m*).
261261
///
262262
/// For expensive key functions (e.g. functions that are not simple property accesses or
263263
/// basic operations), [`sort_by_cached_key`](#method.sort_by_cached_key) is likely to be
@@ -299,8 +299,8 @@ impl<T> [T] {
299299
///
300300
/// During sorting, the key function is called only once per element.
301301
///
302-
/// This sort is stable (i.e., does not reorder equal elements) and `O(m * n + n * log(n))`
303-
/// worst-case, where the key function is `O(m)`.
302+
/// This sort is stable (i.e., does not reorder equal elements) and *O*(*m* \* *n* + *n* \* log(*n*))
303+
/// worst-case, where the key function is *O*(*m*).
304304
///
305305
/// For simple key functions (e.g., functions that are property accesses or
306306
/// basic operations), [`sort_by_key`](#method.sort_by_key) is likely to be
@@ -944,7 +944,7 @@ where
944944
/// 1. for every `i` in `1..runs.len()`: `runs[i - 1].len > runs[i].len`
945945
/// 2. for every `i` in `2..runs.len()`: `runs[i - 2].len > runs[i - 1].len + runs[i].len`
946946
///
947-
/// The invariants ensure that the total running time is `O(n * log(n))` worst-case.
947+
/// The invariants ensure that the total running time is *O*(*n* \* log(*n*)) worst-case.
948948
fn merge_sort<T, F>(v: &mut [T], mut is_less: F)
949949
where
950950
F: FnMut(&T, &T) -> bool,

library/alloc/src/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ use crate::raw_vec::RawVec;
259259
/// `Vec` does not guarantee any particular growth strategy when reallocating
260260
/// when full, nor when [`reserve`] is called. The current strategy is basic
261261
/// and it may prove desirable to use a non-constant growth factor. Whatever
262-
/// strategy is used will of course guarantee `O(1)` amortized [`push`].
262+
/// strategy is used will of course guarantee *O*(1) amortized [`push`].
263263
///
264264
/// `vec![x; n]`, `vec![a, b, c, d]`, and
265265
/// [`Vec::with_capacity(n)`][`Vec::with_capacity`], will all produce a `Vec`

library/core/src/slice/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1945,10 +1945,10 @@ impl<T> [T] {
19451945
///
19461946
/// The comparator function must define a total ordering for the elements in the slice. If
19471947
/// the ordering is not total, the order of the elements is unspecified. An order is a
1948-
/// total order if it is (for all a, b and c):
1948+
/// total order if it is (for all `a`, `b` and `c`):
19491949
///
1950-
/// * total and antisymmetric: exactly one of a < b, a == b or a > b is true; and
1951-
/// * transitive, a < b and b < c implies a < c. The same must hold for both == and >.
1950+
/// * total and antisymmetric: exactly one of `a < b`, `a == b` or `a > b` is true, and
1951+
/// * transitive, `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
19521952
///
19531953
/// For example, while [`f64`] doesn't implement [`Ord`] because `NaN != NaN`, we can use
19541954
/// `partial_cmp` as our sort function when we know the slice doesn't contain a `NaN`.

library/core/src/str/traits.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn str_index_overflow_fail() -> ! {
8989
/// self`. Equivalent to `&self[0 .. len]` or `&mut self[0 .. len]`. Unlike
9090
/// other indexing operations, this can never panic.
9191
///
92-
/// This operation is `O(1)`.
92+
/// This operation is *O*(1).
9393
///
9494
/// Prior to 1.20.0, these indexing operations were still supported by
9595
/// direct implementation of `Index` and `IndexMut`.
@@ -130,7 +130,7 @@ unsafe impl SliceIndex<str> for ops::RangeFull {
130130
/// Returns a slice of the given string from the byte range
131131
/// [`begin`, `end`).
132132
///
133-
/// This operation is `O(1)`.
133+
/// This operation is *O*(1).
134134
///
135135
/// Prior to 1.20.0, these indexing operations were still supported by
136136
/// direct implementation of `Index` and `IndexMut`.
@@ -237,7 +237,7 @@ unsafe impl SliceIndex<str> for ops::Range<usize> {
237237
/// Returns a slice of the given string from the byte range [`0`, `end`).
238238
/// Equivalent to `&self[0 .. end]` or `&mut self[0 .. end]`.
239239
///
240-
/// This operation is `O(1)`.
240+
/// This operation is *O*(1).
241241
///
242242
/// Prior to 1.20.0, these indexing operations were still supported by
243243
/// direct implementation of `Index` and `IndexMut`.
@@ -308,7 +308,7 @@ unsafe impl SliceIndex<str> for ops::RangeTo<usize> {
308308
/// `len`). Equivalent to `&self[begin .. len]` or `&mut self[begin ..
309309
/// len]`.
310310
///
311-
/// This operation is `O(1)`.
311+
/// This operation is *O*(1).
312312
///
313313
/// Prior to 1.20.0, these indexing operations were still supported by
314314
/// direct implementation of `Index` and `IndexMut`.
@@ -385,7 +385,7 @@ unsafe impl SliceIndex<str> for ops::RangeFrom<usize> {
385385
/// self[begin .. end + 1]`, except if `end` has the maximum value for
386386
/// `usize`.
387387
///
388-
/// This operation is `O(1)`.
388+
/// This operation is *O*(1).
389389
///
390390
/// # Panics
391391
///
@@ -441,7 +441,7 @@ unsafe impl SliceIndex<str> for ops::RangeInclusive<usize> {
441441
/// Equivalent to `&self [0 .. end + 1]`, except if `end` has the maximum
442442
/// value for `usize`.
443443
///
444-
/// This operation is `O(1)`.
444+
/// This operation is *O*(1).
445445
///
446446
/// # Panics
447447
///

0 commit comments

Comments
 (0)