diff options
| author | John Schmidt <john.schmidt.h@gmail.com> | 2024-01-27 22:43:35 +0100 |
|---|---|---|
| committer | John Schmidt <john.schmidt.h@gmail.com> | 2024-02-07 21:00:24 +0100 |
| commit | e487b576fadc2fd48100667ff233e4a0bb4f0aa5 (patch) | |
| tree | 27084584f2dd67cb33f5903d2c950f5149f6ce04 /src/codegen/c.zig | |
| parent | 664c18544c2622352a4e38254496a349006d331b (diff) | |
| download | zig-e487b576fadc2fd48100667ff233e4a0bb4f0aa5.tar.gz zig-e487b576fadc2fd48100667ff233e4a0bb4f0aa5.zip | |
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
Diffstat (limited to 'src/codegen/c.zig')
0 files changed, 0 insertions, 0 deletions
