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

unclear behavior of binary search on unsorted structures #106746

Closed
max397574 opened this issue Jan 11, 2023 · 3 comments · Fixed by #106985
Closed

unclear behavior of binary search on unsorted structures #106746

max397574 opened this issue Jan 11, 2023 · 3 comments · Fixed by #106985
Assignees
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@max397574
Copy link

max397574 commented Jan 11, 2023

Location

Local docs from rustup under /std/primitive.slice.html#method.binary_search
also for VecDeque and the other binary search functions (search_by)

Summary

There is written https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.binary_search

Binary searches this slice for a given element. This behaves similarly to contains if this slice is sorted.

To me this first sounded like the binary search would work on all the slices and if it would be sorted sth would be different. Some people told me that it won't work if the slice isn't sorted and it will just output garbage.

If this really is the case it should be written that it only works for sorted slices (and VecDeques).
In any case the different behaviors when sorted and unsorted should be clarified
(e.g. if linear search is done on unsorted slice)

@max397574 max397574 added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Jan 11, 2023
@scottmcm scottmcm added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Jan 13, 2023
@jofas
Copy link
Contributor

jofas commented Jan 13, 2023

I'd be happy to add warnings and examples to the documentation of the binary_search_[by] methods of slice and VecDeque. @scottmcm can I claim this issue?

@workingjubilee
Copy link
Member

@jofas Go for it. In the future you can @ rustbot claim.

@jofas
Copy link
Contributor

jofas commented Jan 16, 2023

thanks @workingjubilee, will do next time 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
4 participants