| author | |
| committer | |
| log | d4dcfdb5ee72d36bdfab22df5c71a51daac69fea |
| tree | f9a870801194eca98cd17df4b40f7a784632c8b3 |
| parent | 49cfaabc101b85d4d282a649c0b9605de20a6229 |
| signature |
2 files changed, 23 insertions(+), 0 deletions(-)
src/compareFnSlice.zig created+22| ... | @@ -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 | } | ||
src/lib.zig+1| ... | @@ -121,3 +121,4 @@ pub usingnamespace @import("./asciiLower.zig"); | ... | @@ -121,3 +121,4 @@ pub usingnamespace @import("./asciiLower.zig"); |
| 121 | pub usingnamespace @import("./parseDigits.zig"); | 121 | pub usingnamespace @import("./parseDigits.zig"); |
| 122 | pub usingnamespace @import("./from_hex.zig"); | 122 | pub usingnamespace @import("./from_hex.zig"); |
| 123 | pub usingnamespace @import("./Pointee.zig"); | 123 | pub usingnamespace @import("./Pointee.zig"); |
| 124 | pub usingnamespace @import("./compareFnSlice.zig"); |