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

std.algorithm: Document sort's predicate expectations #1691

Merged

Conversation

CyberShadow
Copy link
Member

behave as expected - otherwise, the program may fail on certain inputs (but not
others) when not compiled in release mode, due to the cursory $(D assumeSorted)
check. Specifically, $(D sort) expects $(D less(a,b) && less(b,c)) to imply
$(D less(a,c)), and, respectively, $(D !less(a,b) && !less(b,c)) to imply
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/, and, respectively/ (transitivity), and, conversely/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@monarchdodra
Copy link
Collaborator

This is a bit overkill, no? It's longer than the actual documentation...

Can't we just leave it to something like

/++
$(D pred) is expected to define $(WEB wikipedia.org/wiki/Total_order,
total ordering) for $(D input).
Note that the default $(D pred) of $(D "a < b") does
$(I NOT) define total ordering for floating point type
lists containing $(D NaN)s.
+/

@CyberShadow
Copy link
Member Author

Good find regarding the "total order" term, however it doesn't seem to require or imply the negated transitivity property (!(a>b) && !(b>c) implies !(a>c)), which is what NaNs trip up on.

@monarchdodra
Copy link
Collaborator

Good find regarding the "total order" term, however it doesn't seem to require or imply the negated transitivity property (!(a>b) && !(b>c) implies !(a>c)), which is what NaNs trip up on.

We can argue it's implied with transitivity, and/or "strict" total ordering? And the sentence "The default pred does not satisfy this condition" should be hint enough in itself that it is a problem. That we don't need to go into exact details of what fails where.

I don't want to argue too much on documentation though. Do as you wish. Ping us when you feel it's ready.

monarchdodra added a commit that referenced this pull request Nov 18, 2013
…-warning

std.algorithm: Document sort's predicate expectations
@monarchdodra monarchdodra merged commit cc52695 into dlang:master Nov 18, 2013
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