Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lexicographical ordering of sequences #8400

Closed
wants to merge 9 commits into from
Closed

Fix lexicographical ordering of sequences #8400

wants to merge 9 commits into from

Conversation

bluss
Copy link
Member

@bluss bluss commented Aug 8, 2013

Use Eq + Ord for lexicographical ordering of sequences.

For each of <, <=, >= or > as R, use::

[x, ..xs] R [y, ..ys]  =  if x != y { x R y } else { xs R ys }

Previous code using a < b and then !(b < a) for short-circuiting
fails on cases such as [1.0, 2.0] < [0.0/0.0, 3.0], where the first
element was effectively considered equal.

Containers like &[T] did also implement only one comparison operator <,
and derived the comparison results from this. This isn't correct either for
Ord.

Implement functions in std::iterator::order::{lt,le,gt,ge,equal,cmp} that all
iterable containers can use for lexical order.

We also visit tuple ordering, having the same problem and same solution
(but differing implementation).

blake2-ppc added 7 commits August 8, 2013 22:07
Use Eq + Ord for lexicographical ordering of sequences.

For each of <, <=, >= or > as R, use::

    [x, ..xs] R [y, ..ys]  =  if x != y { x R y } else { xs R ys }

Previous code using `a < b` and then `!(b < a)` for short-circuiting
fails on cases such as  [1.0, 2.0] < [0.0/0.0, 3.0], where the first
element was effectively considered equal.
(A,) did not have the trait implementations of 2- to 12- tuples.
Use the definition, where R is <, <=, >=, or >

    [x, ..xs] R [y, ..ys]  =  if x != y { x R y } else { xs R ys }

Previously, tuples would only implement < and derive the other
comparisons from it; this is incorrect. Included are several testcases
involving NaN comparisons that are now correct.

Previously, tuples would consider an element equal if both a < b and
b < a were false, this was also incorrect.
@bluss
Copy link
Member Author

bluss commented Aug 8, 2013

Issue links: #8071, #8360

blake2-ppc added 2 commits August 8, 2013 23:07
Just like the Ord methods, Eq::ne needs to be implemented in terms of
the same operation on the elements.
@emberian
Copy link
Member

This looks good to me, and it seems well-tested.

bors added a commit that referenced this pull request Aug 12, 2013
Use Eq + Ord for lexicographical ordering of sequences.

For each of <, <=, >= or > as R, use::

    [x, ..xs] R [y, ..ys]  =  if x != y { x R y } else { xs R ys }

Previous code using `a < b` and then `!(b < a)` for short-circuiting
fails on cases such as  [1.0, 2.0] < [0.0/0.0, 3.0], where the first
element was effectively considered equal.

Containers like &[T] did also implement only one comparison operator `<`,
and derived the comparison results from this. This isn't correct either for
Ord.

Implement functions in `std::iterator::order::{lt,le,gt,ge,equal,cmp}` that all
iterable containers can use for lexical order.

We also visit tuple ordering, having the same problem and same solution
(but differing implementation).
@bors bors closed this Aug 12, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants