-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
docs(slice): Clarification in binary_search_by #46870
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @withoutboats (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Thanks for the PR! However, I don't think this is a typo. |
@rkruppe |
src/libcore/slice/mod.rs
Outdated
@@ -400,14 +400,14 @@ impl<T> SliceExt for [T] { | |||
while size > 1 { | |||
let half = size / 2; | |||
let mid = base + half; | |||
// mid is always in [0, size). | |||
// mid is always in [0, size]. |
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.
Maybe a connective here, e.g., "mid is always in [0, size), i.e., [bullet points below]"
src/libcore/slice/mod.rs
Outdated
// mid >= 0: by definition | ||
// mid < size: mid = size / 2 + size / 4 + size / 8 ... | ||
let cmp = f(unsafe { s.get_unchecked(mid) }); | ||
base = if cmp == Greater { base } else { mid }; | ||
size -= half; | ||
} | ||
// base is always in [0, size) because base <= mid. | ||
// base is always in [0, size] because base <= mid. |
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.
... and here maybe spell out base < size
?
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.
What do you mean by that?
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.
Was just thinking about how to make this line more explicit, too. But if you don't see the need to change it, that's fine by me too.
@rkruppe |
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.
Changes look basically good. However, I'm afraid I'll have to ask you to squash the commits into one -- generally the project prefers to not have unfinished and "undo this" commits, but rather one commit per finished logical step.
Since you're touching the commits anyway, you might want to consider the subjective style issue below.
src/libcore/slice/mod.rs
Outdated
@@ -400,14 +400,15 @@ impl<T> SliceExt for [T] { | |||
while size > 1 { | |||
let half = size / 2; | |||
let mid = base + half; | |||
// mid is always in [0, size]. | |||
// mid is always in [0, size). | |||
// (that means mid is >= 0 and < size) |
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.
Very minor style nit, but since the lines below are effectively subordinate bullet points, I think it would look nicer if this was one line. Fix if you want, or don't.
No worries! I guess I should have bundled them together with my first comment. What you wrote independently is good too, these were just suggestions. |
@rkruppe |
src/libcore/slice/mod.rs
Outdated
// mid >= 0: by definition | ||
// mid < size: mid = size / 2 + size / 4 + size / 8 ... | ||
let cmp = f(unsafe { s.get_unchecked(mid) }); | ||
base = if cmp == Greater { base } else { mid }; | ||
size -= half; | ||
} | ||
// base is always in [0, size) because base <= mid. | ||
// base is always in [0, size) because base <= mid and base < size. |
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.
Hm, as written that isn't exactly clarifying. Let's just drop it — you're the one who was confused by this and evidently you didn't see the need to clarify this line.
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.
Drop the PR or this line?
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.
This line. The other change is great :)
Great. Thanks again for taking the time, and sorry for all the back and forth ❤️ @bors r+ |
📌 Commit f6ab79d has been approved by |
No worries, thanks for taking your time! 🙂 |
docs(slice): Clarification in binary_search_by This PR ~fixes a small comment typo~ adds some clarification to a half-open interval in the `binary_search_by` function in `slice`.
This PR
fixes a small comment typoadds some clarification to a half-open interval in thebinary_search_by
function inslice
.