Skip to content

Commit

Permalink
Add lexicographical comparison doc
Browse files Browse the repository at this point in the history
Add links

Fix typo

Use `sequence`

Fix typo

Fix broken link

Fix broken link

Fix broken link

Fix broken links

Fix broken links
  • Loading branch information
Rustin170506 committed Oct 26, 2020
1 parent b9a94c9 commit 42844ed
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions library/alloc/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2566,7 +2566,7 @@ __impl_slice_eq1! { [const N: usize] Vec<A>, &[B; N], #[stable(feature = "rust1"
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &[B; N], }
//__impl_slice_eq1! { [const N: usize] Cow<'a, [A]>, &mut [B; N], }

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

/// Implements ordering of vectors, lexicographically.
/// Implements ordering of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison).
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Ord for Vec<T> {
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl<T: PartialOrd, const N: usize> PartialOrd for [T; N] {
}
}

/// Implements comparison of arrays lexicographically.
/// Implements comparison of arrays [lexicographically](Ord#lexicographical-comparison).
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord, const N: usize> Ord for [T; N] {
#[inline]
Expand Down
12 changes: 11 additions & 1 deletion library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,19 @@ impl<T: Ord> Ord for Reverse<T> {
/// ## Derivable
///
/// This trait can be used with `#[derive]`. When `derive`d on structs, it will produce a
/// lexicographic ordering based on the top-to-bottom declaration order of the struct's members.
/// [lexicographic](https://en.wikipedia.org/wiki/Lexicographic_order) ordering based on the top-to-bottom declaration order of the struct's members.
/// When `derive`d on enums, variants are ordered by their top-to-bottom discriminant order.
///
/// ## Lexicographical comparison
///
/// Lexicographical comparison is an operation with the following properties:
/// - Two sequences are compared element by element.
/// - The first mismatching element defines which sequence is lexicographically less or greater than the other.
/// - If one sequence is a prefix of another, the shorter sequence is lexicographically less than the other.
/// - If two sequence have equivalent elements and are of the same length, then the sequences are lexicographically equal.
/// - An empty sequence is lexicographically less than any non-empty sequence.
/// - Two empty sequences are lexicographically equal.
///
/// ## How can I implement `Ord`?
///
/// `Ord` requires that the type also be [`PartialOrd`] and [`Eq`] (which requires [`PartialEq`]).
Expand Down
16 changes: 8 additions & 8 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2851,7 +2851,7 @@ pub trait Iterator {
Product::product(self)
}

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

/// Lexicographically compares the elements of this [`Iterator`] with those
/// [Lexicographically](Ord#lexicographical-comparison) compares the elements of this [`Iterator`] with those
/// of another with respect to the specified comparison function.
///
/// # Examples
Expand Down Expand Up @@ -2925,7 +2925,7 @@ pub trait Iterator {
}
}

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

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

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

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

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

/// Determines if the elements of this [`Iterator`] are lexicographically
/// Determines if the elements of this [`Iterator`] are [lexicographically](Ord#lexicographical-comparison)
/// greater than or equal to those of another.
///
/// # Examples
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/slice/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ where
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Eq> Eq for [T] {}

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

/// Implements comparison of vectors lexicographically.
/// Implements comparison of vectors [lexicographically](Ord#lexicographical-comparison).
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PartialOrd> PartialOrd for [T] {
fn partial_cmp(&self, other: &[T]) -> Option<Ordering> {
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/str/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::ParseBoolError;

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

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

0 comments on commit 42844ed

Please sign in to comment.