aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexis Brodeur <brodeuralexis@gmail.com>2022-09-02 20:56:36 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-02-21 12:28:43 -0500
commit98dd041d536aad1d4936353b4f5e4a2e0aab0fe1 (patch)
tree62e966ccc6156110737c9552b33648993c339d97 /src
parent2737dce84f99a05af51b66fc12794b43dc10fa41 (diff)
downloadzig-98dd041d536aad1d4936353b4f5e4a2e0aab0fe1.tar.gz
zig-98dd041d536aad1d4936353b4f5e4a2e0aab0fe1.zip
Relax `std.sort.binarySearch` requirements
Forcing the key to be of the same type as the sorted items used during the search is a valid use case. There, however, exists some cases where the key and the items are of heterogeneous types, like searching for a code point in ordered ranges of code points: ```zig const CodePoint = u21; const CodePointRange = [2]CodePoint; const valid_ranges = &[_]CodePointRange{ // an ordered array of ranges }; fn orderCodePointAndRange( context: void, code_point: CodePoint, range: CodePointRange ) std.math.Order { _ = context; if (code_point < range[0]) { return .lt; } if (code_point > range[1]) { return .gt; } return .eq; } fn isValidCodePoint(code_point: CodePoint) bool { return std.sort.binarySearch( CodePointRange, code_point, valid_ranges, void, orderCodePointAndRange ) != null; } ``` It is so expected that `std.sort.binarySearch` should therefore support both homogeneous and heterogeneous keys.
Diffstat (limited to 'src')
0 files changed, 0 insertions, 0 deletions