| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | const std = @import("std"); |
| 2 | const extras = @import("./lib.zig"); |
| 3 | |
| 4 | // Remove after updating to Zig 0.17. Ref: https://codeberg.org/ziglang/zig/pulls/32010 |
| 5 | pub 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 | } |