# Changes to lowerBound/upperBound/equalRange · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/e487b576fadc2fd48100667ff233e4a0bb4f0aa5)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: e487b576fadc2fd48100667ff233e4a0bb4f0aa5

Requested commit: e487b576fadc2fd48100667ff233e4a0bb4f0aa5

Commit: e487b576fadc2fd48100667ff233e4a0bb4f0aa5

Tree: 27084584f2dd67cb33f5903d2c950f5149f6ce04

Author: John Schmidt

Committer: John Schmidt

## Message

```
Changes to lowerBound/upperBound/equalRange

The old definitions had some problems:

- In `lowerBound`, the `lhs` (left hand side) argument was passed on the
  right hand side.
- In `upperBound`, the `greaterThan` function needed to return
  `greaterThanOrEqual` for the function work, so either the name or the
  implementation is incorrect.

To fix both problems, define the functions in terms of a `lessThan` function that returns `lhs < rhs`.
The is more consistent with the rest of `sort.zig` and it's also how C++ implements lower/upperBound (1)(2).

(1) https://en.cppreference.com/w/cpp/algorithm/lower_bound
(2) https://en.cppreference.com/w/cpp/algorithm/upper_bound

- Rewrite doc comments.
- Add a couple of more test cases.
- Add docstring for std.sort.binarySearch

```

## Parents

- [664c18544c2622352a4e38254496a349006d331b](https://git.cafe/gitcafe/zig/commit/664c18544c2622352a4e38254496a349006d331b?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/e487b576fadc2fd48100667ff233e4a0bb4f0aa5?format=markdown)
