Skip to content
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

Updated Binary Search docs to show insert into an already sorted list #61742

Closed
wants to merge 2 commits into from

Conversation

ptallo
Copy link

@ptallo ptallo commented Jun 11, 2019

Resolves: #61684

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 11, 2019
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
src/libcore/slice/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@jonas-schievink jonas-schievink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but let's wait for someone on the docs/libs team to look over it. Thanks for the PR :)

@ptallo
Copy link
Author

ptallo commented Jun 11, 2019

No problem! Thanks for the review help, grammar isn't my strong suit!

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:05867abf:start=1560273737566163403,finish=1560273826258058461,duration=88691895058
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[00:04:02] tidy error: /checkout/src/libcore/slice/mod.rs:1379: trailing whitespace
[00:04:07] some tidy checks failed
[00:04:07] 
[00:04:07] 
[00:04:07] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:04:07] 
[00:04:07] 
[00:04:07] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:07] Build completed unsuccessfully in 0:01:12
---
travis_time:end:0f142a37:start=1560274084637241665,finish=1560274084641809418,duration=4567753
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0c6102ae
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:071f3811
travis_time:start:071f3811
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:150a6366
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@ondj
Copy link

ondj commented Jun 12, 2019

Why something like this?

if let Err(pos) = s.binary_search(&num) {
    s.insert(pos, num);
}

…ed list

Resolves: rust-lang#61684

Apply suggestions from code review

Co-Authored-By: Jonas Schievink <jonasschievink@gmail.com>

Cleanup: Fixed failing tidy checks
@ptallo
Copy link
Author

ptallo commented Jun 12, 2019

was squashing cleanup commits into one commit, and @ondj I believe that would work as well, this way just seemed like it would allow more modification (editing of the OK() or Err() blocks)

@czipperz
Copy link
Contributor

Ping @ptallo

/// let num = 14;
///
/// match s.binary_search(&num) {
/// Ok(_) => {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think we should be inserting regardless of finding the item here, so filling out this Ok branch with an insert as well would be good, perhaps even illustrating that by doing something like Ok(idx) | Err(idx) => s.insert(idx, num) in an if let.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe my new commit is more what you were looking for. Do I need to squash the commits or will the merge do that for me?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to squash the commits; it also looks like you have a build failure here -- I suspect the ; after the if let.

@Mark-Simulacrum
Copy link
Member

r? @Mark-Simulacrum

I'll take over review here for now, left a comment.

/// let num = 14;
///
/// let idx = s.binary_search(&num);
/// if let Ok(idx) | Err(idx) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is invalid syntax and should be if let Ok(idx) | Err(idx) = idx {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See error:

error: expected one of `=` or `|`, found `{`
 --> slice/mod.rs:1361:27
  |
8 | if let Ok(idx) | Err(idx) {
  |                           ^ expected one of `=` or `|` here

///
/// let idx = s.binary_search(&num);
/// if let Ok(idx) | Err(idx) {
/// s.insert(idx, num)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There have been losed a semicolon
s.insert(idx,num);

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 26, 2019
@totsteps
Copy link
Member

ping from triage, @ptallo any updates on this?

@fmckeogh
Copy link
Member

fmckeogh commented Aug 6, 2019

Hello! Second ping from triage, @ptallo please feel free to reopen when you have the time (Also note that pushing to the PR while it is closed prevents it from being reopened).

@rustbot modify labels to +S-inactive-closed, -S-waiting-on-author

@fmckeogh fmckeogh closed this Aug 6, 2019
@rustbot rustbot added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 6, 2019
@tesuji
Copy link
Contributor

tesuji commented Aug 10, 2019

I rework in #63442.

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Aug 11, 2019
…k-Simulacrum

Add an example to show how to insert item to a sorted vec

Closes rust-lang#61684
cc rust-lang#61742
r? @Mark-Simulacrum, @jonas-schievink
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Aug 11, 2019
…k-Simulacrum

Add an example to show how to insert item to a sorted vec

Closes rust-lang#61684
cc rust-lang#61742
r? @Mark-Simulacrum, @jonas-schievink
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.
Projects
None yet