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
Tracking issue for RFC 2351, "Add is_sorted
to the standard library"
#53485
Comments
@gnzlbg Would you be interested in implementing this? You basically already wrote the code. I think it would be fancy to have this SIMD code in the standard library. (Or should we start with only the fully generic algorithm?). PS: Sorry for not having reviewed #53386 yet -- I hope I'll find the time and mental capacity to do that in the near future! @Centril The links for the unresolved questions are dead (still pointing to the 0000 file). Could you or anyone update them? :) Regarding the "Should
And people seem to agree. So I'd also say that this method should be added. |
@LukasKalbertodt done :) |
cc @SimonSapin re. the unresolved questions (particularly around |
I don't know when I can work on this, but I can mentor anyone wanting to implement this or wanting to port the implementation of the |
Oh, I didn’t realized that We do have precedent of adding some APIs that can be expressed as a terse combination of existing APIs: #49098 @clarcharr, you expressed the opposite in rust-lang/rfcs#2351 (comment). Do you still think it should not be included? |
At the time I made that comment, I didn't realise that
I feel like the usefulness of these should be re-evaluated, as it forces the key to outlive any reference to Personally, I'd prefer option 1. But option 2 is also acceptable and there may be a way to make these functions work with GAT in the future. |
@SimonSapin would you like to be the reviewer of a PR implementing this ? If so, I'd like to discuss with somebody first how the is_sorted crate is structure, and how to best implement this functionality in the std library. |
So I don't know how to properly implement this in The After talking with @SimonSapin on IRC, I am just going to add the naive versions to |
I have interest in working on this RFC. This would be a significant learning experience for me, but I don't see any reason why I should not be able to complete it. @gnzlbg If your offer for being available as a mentor is still open, I'd like to take you up on that! If there is any concern in timeline (I should be able to begin implementing this week) or preference for someone who may have more experience, I have no problem with that; just let me know! |
An efficient implementation of this is probably blocked on rust-lang/rfcs#2492 (e.g. see rust-lang/rfcs#2492 (comment)) , since until then we cannot really use SIMD in My recommendation is that if you want to implement this now, you should just adapt rust-itertools/itertools#261 which is a straight-forward plain Rust implementation. Maybe with some tweaks one can get it to auto-vectorize in some cases. This would allow us to get experience with the API until the other problems are solved. |
Thanks for the links; it makes sense that a more efficient implementation is blocked on that right now. To clarify on my initial comment (and what you picked up on in your last sentence), is the "learning" part of this would be more related to familiarizing myself with the API and codebase. I think an initial implementation based off rust-itertools/itertools#261 could be a good first step and we'll keep an eye on the progress of rust-lang/rfcs#2492? |
@SimonSapin It was asked a few comments up if you'd like to be the reviewer of this PR? I still need to assign someone to review it, but I'm just not sure who. |
Add `is_sorted` to `Iterator` and `[T]` This is an initial implementation for the first step of [RFC 2351](https://github.com/rust-lang/rfcs/blob/master/text/2351-is-sorted.md) Tracking issue: #53485
This has broken the is_sorted crate on nightly. Is the only workaround to turn the feature flag on or use an older nightly?
|
Call IsSorted::is_sorted directly. |
@clarcharr The above error happens when adding |
You can send a PR to the is_sorted crate and use the patch section in your Cargo.toml in the meantime until it is merged and published. |
@mtak- thank you for the PR, i've merged it already, will fix the doc tests and do a release so that the world keeps going. The collision between the |
remove HRTB from `[T]::is_sorted_by{,_key}` Changes the signature of `[T]::is_sorted_by{,_key}` to match `[T]::binary_search_by{,_key}` and make code like rust-lang#53485 (comment) compile. Tracking issue: rust-lang#53485 ~~Do we need an ACP for something like this?~~ Edit: Filed ACP here: rust-lang/libs-team#121
remove HRTB from `[T]::is_sorted_by{,_key}` Changes the signature of `[T]::is_sorted_by{,_key}` to match `[T]::binary_search_by{,_key}` and make code like rust-lang#53485 (comment) compile. Tracking issue: rust-lang#53485 ~~Do we need an ACP for something like this?~~ Edit: Filed ACP here: rust-lang/libs-team#121
remove HRTB from `[T]::is_sorted_by{,_key}` Changes the signature of `[T]::is_sorted_by{,_key}` to match `[T]::binary_search_by{,_key}` and make code like rust-lang#53485 (comment) compile. Tracking issue: rust-lang#53485 ~~Do we need an ACP for something like this?~~ Edit: Filed ACP here: rust-lang/libs-team#121
remove HRTB from `[T]::is_sorted_by{,_key}` Changes the signature of `[T]::is_sorted_by{,_key}` to match `[T]::binary_search_by{,_key}` and make code like rust-lang#53485 (comment) compile. Tracking issue: rust-lang#53485 ~~Do we need an ACP for something like this?~~ Edit: Filed ACP here: rust-lang/libs-team#121
If slice::sort uses F: FnMut(&T, &T) -> Ordering, then perhaps is_sorted_by could use the same. |
remove HRTB from `[T]::is_sorted_by{,_key}` Changes the signature of `[T]::is_sorted_by{,_key}` to match `[T]::binary_search_by{,_key}` and make code like rust-lang/rust#53485 (comment) compile. Tracking issue: rust-lang/rust#53485 ~~Do we need an ACP for something like this?~~ Edit: Filed ACP here: rust-lang/libs-team#121
A suggestion: Rust compiler should raise a compiler error when is_sorted or one of the related functions is called on keys or values of a |
Depending on the order of items in a HashMap isn't UB; the order is just not guaranteed. The difference here is one thing is unsafe and one is just a bad idea. |
…r=cuviper Add more comprehensive tests for is_sorted and friends See rust-lang#53485 and rust-lang#55045.
"Revisit test suite" can probably be checked off due to #112699. I feel like this could probably be stabilized as-is, and more could be added in later. |
Nominating for Note: while trying to check the implementation history I've updated the issue text with the newer format, hopefully it makes it easier to understand what this issue tracks, exactly. While doing that I've also found two questions in the comments that did not seem to be fully answered:
|
We dicsussed this in a recent libs-api meeting.
|
This was already mentioned earlier, but |
…Simulacrum Use `bool` instead of `PartiolOrd` as return value of the comparison closure in `{slice,Iteraotr}::is_sorted_by` Changes the function signature of the closure given to `{slice,Iteraotr}::is_sorted_by` to return a `bool` instead of a `PartiolOrd` as suggested by the libs-api team here: rust-lang#53485 (comment). This means these functions now return true if the closure returns true for all the pairs of values.
Rollup merge of rust-lang#118811 - EbbDrop:is-sorted-by-bool, r=Mark-Simulacrum Use `bool` instead of `PartiolOrd` as return value of the comparison closure in `{slice,Iteraotr}::is_sorted_by` Changes the function signature of the closure given to `{slice,Iteraotr}::is_sorted_by` to return a `bool` instead of a `PartiolOrd` as suggested by the libs-api team here: rust-lang#53485 (comment). This means these functions now return true if the closure returns true for all the pairs of values.
Use `bool` instead of `PartiolOrd` as return value of the comparison closure in `{slice,Iteraotr}::is_sorted_by` Changes the function signature of the closure given to `{slice,Iteraotr}::is_sorted_by` to return a `bool` instead of a `PartiolOrd` as suggested by the libs-api team here: rust-lang/rust#53485 (comment). This means these functions now return true if the closure returns true for all the pairs of values.
Use `bool` instead of `PartiolOrd` as return value of the comparison closure in `{slice,Iteraotr}::is_sorted_by` Changes the function signature of the closure given to `{slice,Iteraotr}::is_sorted_by` to return a `bool` instead of a `PartiolOrd` as suggested by the libs-api team here: rust-lang/rust#53485 (comment). This means these functions now return true if the closure returns true for all the pairs of values.
Feature gate:
#![feature(is_sorted)]
This is a tracking issue for
is_sorted{_by,_by_key}
functions on[T]
andIterator
(rust-lang/rfcs#2351).Public API
Steps / History
is_sorted
toIterator
and[T]
#55045[T]::is_sorted_by{,_key}
#102977Unresolved Questions
Ord
instead of onlyPartialOrd
?is_sorted[_by_key]
requireOrd
instead ofPartialOrd
and removeIterator::is_sorted_by_key
#81382 (comment) (no,PartialOrd
is the right bound)Iterator::is_sorted_by_key
be added as well?std::cmp::is_sorted
instead?is_sorted_by
take a closure returningbool
instead ofOption<Ordering>
?Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: