Skip to content

Commit 727e93d

Browse files
authored
Rollup merge of #78347 - Rustin-Liu:rustin-patch-doc, r=kennytm
Add lexicographical comparison doc close #72255
2 parents afdd148 + 42844ed commit 727e93d

File tree

6 files changed

+26
-16
lines changed

6 files changed

+26
-16
lines changed

library/alloc/src/vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2566,7 +2566,7 @@ __impl_slice_eq1! { [const N: usize] Vec<A>, &[B; N], #[stable(feature = "rust1"
25662566
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &[B; N], }
25672567
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &mut [B; N], }
25682568

2569-
/// Implements comparison of vectors, lexicographically.
2569+
/// Implements comparison of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison).
25702570
#[stable(feature = "rust1", since = "1.0.0")]
25712571
impl<T: PartialOrd> PartialOrd for Vec<T> {
25722572
#[inline]
@@ -2578,7 +2578,7 @@ impl<T: PartialOrd> PartialOrd for Vec<T> {
25782578
#[stable(feature = "rust1", since = "1.0.0")]
25792579
impl<T: Eq> Eq for Vec<T> {}
25802580

2581-
/// Implements ordering of vectors, lexicographically.
2581+
/// Implements ordering of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison).
25822582
#[stable(feature = "rust1", since = "1.0.0")]
25832583
impl<T: Ord> Ord for Vec<T> {
25842584
#[inline]

library/core/src/array/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<T: PartialOrd, const N: usize> PartialOrd for [T; N] {
344344
}
345345
}
346346

347-
/// Implements comparison of arrays lexicographically.
347+
/// Implements comparison of arrays [lexicographically](Ord#lexicographical-comparison).
348348
#[stable(feature = "rust1", since = "1.0.0")]
349349
impl<T: Ord, const N: usize> Ord for [T; N] {
350350
#[inline]

library/core/src/cmp.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,19 @@ impl<T: Ord> Ord for Reverse<T> {
506506
/// ## Derivable
507507
///
508508
/// This trait can be used with `#[derive]`. When `derive`d on structs, it will produce a
509-
/// lexicographic ordering based on the top-to-bottom declaration order of the struct's members.
509+
/// [lexicographic](https://en.wikipedia.org/wiki/Lexicographic_order) ordering based on the top-to-bottom declaration order of the struct's members.
510510
/// When `derive`d on enums, variants are ordered by their top-to-bottom discriminant order.
511511
///
512+
/// ## Lexicographical comparison
513+
///
514+
/// Lexicographical comparison is an operation with the following properties:
515+
/// - Two sequences are compared element by element.
516+
/// - The first mismatching element defines which sequence is lexicographically less or greater than the other.
517+
/// - If one sequence is a prefix of another, the shorter sequence is lexicographically less than the other.
518+
/// - If two sequence have equivalent elements and are of the same length, then the sequences are lexicographically equal.
519+
/// - An empty sequence is lexicographically less than any non-empty sequence.
520+
/// - Two empty sequences are lexicographically equal.
521+
///
512522
/// ## How can I implement `Ord`?
513523
///
514524
/// `Ord` requires that the type also be [`PartialOrd`] and [`Eq`] (which requires [`PartialEq`]).

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -2851,7 +2851,7 @@ pub trait Iterator {
28512851
Product::product(self)
28522852
}
28532853

2854-
/// Lexicographically compares the elements of this [`Iterator`] with those
2854+
/// [Lexicographically](Ord#lexicographical-comparison) compares the elements of this [`Iterator`] with those
28552855
/// of another.
28562856
///
28572857
/// # Examples
@@ -2873,7 +2873,7 @@ pub trait Iterator {
28732873
self.cmp_by(other, |x, y| x.cmp(&y))
28742874
}
28752875

2876-
/// Lexicographically compares the elements of this [`Iterator`] with those
2876+
/// [Lexicographically](Ord#lexicographical-comparison) compares the elements of this [`Iterator`] with those
28772877
/// of another with respect to the specified comparison function.
28782878
///
28792879
/// # Examples
@@ -2925,7 +2925,7 @@ pub trait Iterator {
29252925
}
29262926
}
29272927

2928-
/// Lexicographically compares the elements of this [`Iterator`] with those
2928+
/// [Lexicographically](Ord#lexicographical-comparison) compares the elements of this [`Iterator`] with those
29292929
/// of another.
29302930
///
29312931
/// # Examples
@@ -2949,7 +2949,7 @@ pub trait Iterator {
29492949
self.partial_cmp_by(other, |x, y| x.partial_cmp(&y))
29502950
}
29512951

2952-
/// Lexicographically compares the elements of this [`Iterator`] with those
2952+
/// [Lexicographically](Ord#lexicographical-comparison) compares the elements of this [`Iterator`] with those
29532953
/// of another with respect to the specified comparison function.
29542954
///
29552955
/// # Examples
@@ -3089,7 +3089,7 @@ pub trait Iterator {
30893089
!self.eq(other)
30903090
}
30913091

3092-
/// Determines if the elements of this [`Iterator`] are lexicographically
3092+
/// Determines if the elements of this [`Iterator`] are [lexicographically](Ord#lexicographical-comparison)
30933093
/// less than those of another.
30943094
///
30953095
/// # Examples
@@ -3110,7 +3110,7 @@ pub trait Iterator {
31103110
self.partial_cmp(other) == Some(Ordering::Less)
31113111
}
31123112

3113-
/// Determines if the elements of this [`Iterator`] are lexicographically
3113+
/// Determines if the elements of this [`Iterator`] are [lexicographically](Ord#lexicographical-comparison)
31143114
/// less or equal to those of another.
31153115
///
31163116
/// # Examples
@@ -3131,7 +3131,7 @@ pub trait Iterator {
31313131
matches!(self.partial_cmp(other), Some(Ordering::Less | Ordering::Equal))
31323132
}
31333133

3134-
/// Determines if the elements of this [`Iterator`] are lexicographically
3134+
/// Determines if the elements of this [`Iterator`] are [lexicographically](Ord#lexicographical-comparison)
31353135
/// greater than those of another.
31363136
///
31373137
/// # Examples
@@ -3152,7 +3152,7 @@ pub trait Iterator {
31523152
self.partial_cmp(other) == Some(Ordering::Greater)
31533153
}
31543154

3155-
/// Determines if the elements of this [`Iterator`] are lexicographically
3155+
/// Determines if the elements of this [`Iterator`] are [lexicographically](Ord#lexicographical-comparison)
31563156
/// greater than or equal to those of another.
31573157
///
31583158
/// # Examples

library/core/src/slice/cmp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ where
3535
#[stable(feature = "rust1", since = "1.0.0")]
3636
impl<T: Eq> Eq for [T] {}
3737

38-
/// Implements comparison of vectors lexicographically.
38+
/// Implements comparison of vectors [lexicographically](Ord#lexicographical-comparison).
3939
#[stable(feature = "rust1", since = "1.0.0")]
4040
impl<T: Ord> Ord for [T] {
4141
fn cmp(&self, other: &[T]) -> Ordering {
4242
SliceOrd::compare(self, other)
4343
}
4444
}
4545

46-
/// Implements comparison of vectors lexicographically.
46+
/// Implements comparison of vectors [lexicographically](Ord#lexicographical-comparison).
4747
#[stable(feature = "rust1", since = "1.0.0")]
4848
impl<T: PartialOrd> PartialOrd for [T] {
4949
fn partial_cmp(&self, other: &[T]) -> Option<Ordering> {

library/core/src/str/traits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::ParseBoolError;
99

1010
/// Implements ordering of strings.
1111
///
12-
/// Strings are ordered lexicographically by their byte values. This orders Unicode code
12+
/// Strings are ordered [lexicographically](Ord#lexicographical-comparison) by their byte values. This orders Unicode code
1313
/// points based on their positions in the code charts. This is not necessarily the same as
1414
/// "alphabetical" order, which varies by language and locale. Sorting strings according to
1515
/// culturally-accepted standards requires locale-specific data that is outside the scope of
@@ -39,7 +39,7 @@ impl Eq for str {}
3939

4040
/// Implements comparison operations on strings.
4141
///
42-
/// Strings are compared lexicographically by their byte values. This compares Unicode code
42+
/// Strings are compared [lexicographically](Ord#lexicographical-comparison) by their byte values. This compares Unicode code
4343
/// points based on their positions in the code charts. This is not necessarily the same as
4444
/// "alphabetical" order, which varies by language and locale. Comparing strings according to
4545
/// culturally-accepted standards requires locale-specific data that is outside the scope of

0 commit comments

Comments
 (0)