authorgravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-01-17 19:32:43+01:00
committergravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-01-17 21:42:32+01:00
log26de7a3513901dcdd5a5d588a2f38f25fda0e626
tree894e88eb5d5cebc3074484395ae0ce645149ddaa
parent27685bcf2097605be7bcb6d1e16e2f4747a1a841
signaturebadge-check Signed by SSH key SHA256:p3IHbr0lyK2ekfDC1Zi7dOEV/9T6lGghNawhl5sBnM4

feat(std.mem): add `boundedOrderZ`


1 files changed, 7 insertions(+), 2 deletions(-)

lib/std/mem.zig+7-2
...@@ -662,10 +662,15 @@ pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order {...@@ -662,10 +662,15 @@ pub fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order {
662662
663/// Compares two many-item pointers with NUL-termination lexicographically.663/// Compares two many-item pointers with NUL-termination lexicographically.
664pub fn orderZ(comptime T: type, lhs: [*:0]const T, rhs: [*:0]const T) math.Order {664pub fn orderZ(comptime T: type, lhs: [*:0]const T, rhs: [*:0]const T) math.Order {
665 return boundedOrderZ(T, lhs, rhs, std.math.maxInt(usize));
666}
667
668/// Compares two many-item pointers with NUL-termination lexicographically until some specified bound.
669pub fn boundedOrderZ(comptime T: type, lhs: [*:0]const T, rhs: [*:0]const T, bound: usize) math.Order {
665 if (lhs == rhs) return .eq;670 if (lhs == rhs) return .eq;
666 var i: usize = 0;671 var i: usize = 0;
667 while (lhs[i] == rhs[i] and lhs[i] != 0) : (i += 1) {}672 while (lhs[i] == rhs[i] and lhs[i] != 0 and i < bound) : (i += 1) {}
668 return math.order(lhs[i], rhs[i]);673 return if (i < bound) math.order(lhs[i], rhs[i]) else .eq;
669}674}
670675
671test order {676test order {