-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add Iterator::partition_in_place() and is_partitioned() #62278
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
|
These are inspired by C++
Implementation note: C++ allows C++ does talk about bi-directional modes too, which I imagine would work like what I have here.
I'm open to renaming. I don't think an |
Ah -- in that case I think |
I would have used |
There's also I wonder if we might also want an index from |
(That wouldn't have been very appropriate imo as our naming is primarily Haskell based...) |
OK, that's 3 votes for |
This looks great to me, thanks @cuviper! Could a few more tests be included as well beyond the doc tests? Otherwise API-wise would it be feasible to return a |
Thanks for the review -- sorry I didn't get back to this yet. I can definitely add more tests, and I think |
`partition_mut()` swaps `&mut T` items in-place to satisfy the predicate, so all `true` items precede all `false` items. This requires a `DoubleEndedIterator` so we can search from front and back for items that need swapping. `is_partitioned()` checks whether the predicate is already satisfied.
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
OK, ready for another review. |
// FIXME: should we worry about the count overflowing? The only way to have more than | ||
// `usize::MAX` mutable references is with ZSTs, which aren't useful to partition... | ||
|
||
// These closure "factory" functions exist to avoid genericity in `Self`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On this, see also #62429.
Looks great to me, thanks @cuviper! r=me with the tracking issue numbers filled in |
Done! @bors r=alexcrichton |
📌 Commit 7171c83 has been approved by |
Add Iterator::partition_in_place() and is_partitioned() `partition_in_place()` swaps `&mut T` items in-place to satisfy the predicate, so all `true` items precede all `false` items. This requires a `DoubleEndedIterator` so we can search from front and back for items that need swapping. `is_partitioned()` checks whether the predicate is already satisfied.
Rollup of 5 pull requests Successful merges: - #61853 (Emit warning when trying to use PGO in conjunction with unwinding on …) - #62278 (Add Iterator::partition_in_place() and is_partitioned()) - #62283 (Target::arch can take more than listed options) - #62393 (Fix pretty-printing of `$crate` (take 4)) - #62474 (Prepare for LLVM 9 update) Failed merges: r? @ghost
partition_in_place()
swaps&mut T
items in-place to satisfy thepredicate, so all
true
items precede allfalse
items. This requiresa
DoubleEndedIterator
so we can search from front and back for itemsthat need swapping.
is_partitioned()
checks whether the predicate is already satisfied.