authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-21 04:10:32 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-21 04:10:32 -07:00
logc2c581aa6a38438dd9ed8da0f59019691c5dd45d
treeb78ad413b2f27549c2ffe2f11a9058b135bd5d12
parent80b0532a431e4780ccb666c4c08bf9be0277bc00
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add sumLen


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

src/lib.zig+2
...@@ -122,6 +122,7 @@ pub const parseDigits = @import("./parseDigits.zig").parseDigits;...@@ -122,6 +122,7 @@ pub const parseDigits = @import("./parseDigits.zig").parseDigits;
122pub const from_hex = @import("./from_hex.zig").from_hex;122pub const from_hex = @import("./from_hex.zig").from_hex;
123pub const Pointee = @import("./Pointee.zig").Pointee;123pub const Pointee = @import("./Pointee.zig").Pointee;
124pub const compareFnSlice = @import("./compareFnSlice.zig").compareFnSlice;124pub const compareFnSlice = @import("./compareFnSlice.zig").compareFnSlice;
125pub const sumLen = @import("./sumLen.zig").sumLen;
125126
126test {127test {
127 _ = @import("reduceNumber.zig");128 _ = @import("reduceNumber.zig");
...@@ -216,4 +217,5 @@ test {...@@ -216,4 +217,5 @@ test {
216 _ = @import("from_hex.zig");217 _ = @import("from_hex.zig");
217 _ = @import("Pointee.zig");218 _ = @import("Pointee.zig");
218 _ = @import("compareFnSlice.zig");219 _ = @import("compareFnSlice.zig");
220 _ = @import("sumLen.zig");
219}221}
src/sumLen.zig created+28
...@@ -0,0 +1,28 @@
1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn sumLen(comptime T: type, slice: []const []const T) u64 {
6 var res: u64 = 0;
7 for (slice) |item| res += item.len;
8 return res;
9}
10
11test {
12 try std.testing.expect(sumLen(u8, &.{ &.{4}, &.{3}, &.{0}, &.{9}, &.{6}, &.{7}, &.{1}, &.{2}, &.{5}, &.{8} }) == 10);
13}
14test {
15 try std.testing.expect(sumLen(u16, &.{ &.{ 8, 6 }, &.{ 7, 3 }, &.{ 2, 1 }, &.{ 5, 0 }, &.{ 9, 4 } }) == 10);
16}
17test {
18 try std.testing.expect(sumLen(u21, &.{ &.{ 5, 4, 6 }, &.{ 1, 8, 3, 2 }, &.{ 9, 0, 7 } }) == 10);
19}
20test {
21 try std.testing.expect(sumLen(u32, &.{ &.{ 3, 4 }, &.{ 5, 1, 9, 0, 6, 2, 7, 8 } }) == 10);
22}
23test {
24 try std.testing.expect(sumLen(u40, &.{ &.{ 0, 5, 6, 7, 1, 2 }, &.{ 4, 9, 3, 8 } }) == 10);
25}
26test {
27 try std.testing.expect(sumLen(u64, &.{&.{ 5, 4, 3, 9, 1, 7, 6, 2, 0, 8 }}) == 10);
28}