Add Iterator::partition_in_place() and is_partitioned()#62278
Add Iterator::partition_in_place() and is_partitioned()#62278bors merged 7 commits intorust-lang:masterfrom
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`. |
|
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 Titems in-place to satisfy thepredicate, so all
trueitems precede allfalseitems. This requiresa
DoubleEndedIteratorso we can search from front and back for itemsthat need swapping.
is_partitioned()checks whether the predicate is already satisfied.