Make clarifications for `binary_search` API
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Location
https://doc.rust-lang.org/std/primitive.slice.html#method.binary_search
Summary
Documentation states, that
If the slice is not sorted, the returned result is unspecified and meaningless.
but if we try to use binary search on something like [5,4,3,2,1].binary_search(&5) it will end up with error, though the slice is sorted in descending order.
This either requires to fix docs to something like
If the slice is not sorted in ascending order, the returned result is unspecified and meaningless.
or fix actual binary search algorithm by flipping direction of search in case left and right bounds are flipped.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the linked std::slice::binary_search documentation and review the wording about sorted slices against the reported descending-order example. Clarify the documented ordering requirement if that is the intended scope; the issue also raises an alternative algorithm change, so confirm the expected resolution before editing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100