-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 partition_point
#73831
Comments
In order to deduplicate this code with use crate::cmp::Ordering::{Less, Greater};
impl<T> [T] {
pub fn partition_point<P>(&self, mut pred: P) -> usize
where
P: FnMut(&T) -> bool,
{
self.binary_search_by(|x| if pred(x) { Less } else { Greater })
.unwrap_or_else(|i| i)
}
} |
I prefer my I tried
In addition, I also tried to
I'm not sure succeeded to remove, or possibly already done from current code. https://github.com/VillSnow/compare-binary-searches/blob/master/src/main.rs You can find logic1, 3, 4 need 3 comparisons to find from 0..7, while logic2 needs 4 calls. Here is a typical result of bench. Find 0 from 0..65536 and find 0 from 7 but inserted sleep(1ms) in comparison.
|
I believe this is intended, it is not optimized for doing the minimum number of comparisons. Make sure to run the benchmarks in https://github.com/rust-lang/rust/blob/master/src/libcore/benches/slice.rs before drawing any conclusions. And regardless of what the ideal implementation of |
AFAIK, this bench is written when logic1 is replaced into logic2, not after logic3. The bench tries to find random element from usize slice, not user type which needs large cost to compare.
Is it means |
I noticed in passing that this is using Though I guess |
@scottmcm memoization or exterior (web/DB) API access using mut handle? |
@VillSnow this has been baking in the nightly for a while, I think this is ready for stabilization. Would like to send a stabilization PR? |
If the team think all right, I'm glad. I still concern about code duplication, and I'm watching this PR #74024. I have no objection to merge this. |
Submitting a stabilization PR is a way to figure that out! I am not on the libs team, but this seems stabilization-worthy to me. I wouldn't worry about impl details -- they can be adjusted after stabilization. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Moved from #81012: @dtolnay's comment (#81012 (comment)):
@rfcbot fcp merge |
Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@rfcbot concern name I was completly unaware we even had this function, and even suggested a few times we might want to add something like this. I guess because the name doesn't remind me of a binary search. This at least means that we should update the documentation of |
I second @m-ou-se's naming concern. My first reaction was, "what the heck is a partition point?" I think my preference would be to have "binary search" or at least "search" in the name somewhere. A bit verbose, but maybe |
The first reason why this is Otherwise, this example shows what it gets is the partition point. #![feature(partition_point)]
use std::iter::Iterator;
fn main() {
let mut s = [2, 7, 1, 8, 2, 8, 1, 8, 2, 8, 4];
let a = itertools::partition(&mut s, |x| *x > 5);
for (i, x) in s.iter().enumerate() {
print!("{}{}", if i == a { "|" } else { " " }, x);
}
// 8 7 8 8 8|2 1 1 2 2 4
let b = s.partition_point(|x| *x > 5);
assert_eq!(a, b); // pass
} If the method named partition_point: The idea of partition is uncommon. |
If I remember correctly, we had a long bikeshed over the name and ended up following C++ as a tie-breaker. |
FWIW, we've had Barring something obviously better (which doesn't seem forthcoming), using the C++ name seems reasonable. A documentation update to crosslink this from (Hopefully this method can be resolved without a broader binary search conversation, but if not then I think it should include some sort of plan for |
FWIW, my secret plan is to just submit a pr implementing |
Sounds like this is the best name we can come up with. So, let's make sure the documentation of the If anybody feels like updating the documentation here: PRs welcome. ^^ Let's kick off the FCP for stabilizing this: @rfcbot resolve name |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
I don't know much about It looks like to make a flow from other names. For example, some languages has |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
… r=matklad Stabilize the partition_point feature Stabilize the partition_point feature. Tracking Issue: rust-lang#73831 First PR: rust-lang#73577
Thanks for much assistance. |
Feature gate:
#![feature(partition_point)]
This is a tracking issue for
[T]::partition_point
.See also rust-lang/rfcs#2184
Public API
Steps / History
partition_point
#73831 (comment)binary_search
(and/orbinary_search_by
) to point out the existence of this function too.Unresolved Questions
partition_point
matches C++, but might be hard to recognize as a binary search.The text was updated successfully, but these errors were encountered: