authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-21 21:56:16 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-04-21 21:56:16 -07:00
logd4dcfdb5ee72d36bdfab22df5c71a51daac69fea
treef9a870801194eca98cd17df4b40f7a784632c8b3
parent49cfaabc101b85d4d282a649c0b9605de20a6229
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add compareFnSlice


2 files changed, 23 insertions(+), 0 deletions(-)

src/compareFnSlice.zig created+22
...@@ -0,0 +1,22 @@
1const std = @import("std");
2const extras = @import("./lib.zig");
3
4// Remove after updating to Zig 0.17. Ref: https://codeberg.org/ziglang/zig/pulls/32010
5pub fn compareFnSlice(comptime T: type) fn ([]const T, []const T) std.math.Order {
6 const S = struct {
7 fn order(lhs: []const T, rhs: []const T) std.math.Order {
8 if (lhs.ptr != rhs.ptr) {
9 const n = @min(lhs.len, rhs.len);
10 for (lhs[0..n], rhs[0..n]) |lhs_elem, rhs_elem| {
11 switch (std.math.order(lhs_elem, rhs_elem)) {
12 .eq => continue,
13 .lt => return .lt,
14 .gt => return .gt,
15 }
16 }
17 }
18 return std.math.order(lhs.len, rhs.len);
19 }
20 };
21 return S.order;
22}
src/lib.zig+1
...@@ -121,3 +121,4 @@ pub usingnamespace @import("./asciiLower.zig");...@@ -121,3 +121,4 @@ pub usingnamespace @import("./asciiLower.zig");
121pub usingnamespace @import("./parseDigits.zig");121pub usingnamespace @import("./parseDigits.zig");
122pub usingnamespace @import("./from_hex.zig");122pub usingnamespace @import("./from_hex.zig");
123pub usingnamespace @import("./Pointee.zig");123pub usingnamespace @import("./Pointee.zig");
124pub usingnamespace @import("./compareFnSlice.zig");