| author | |
| committer | |
| log | c2c581aa6a38438dd9ed8da0f59019691c5dd45d |
| tree | b78ad413b2f27549c2ffe2f11a9058b135bd5d12 |
| parent | 80b0532a431e4780ccb666c4c08bf9be0277bc00 |
| signature |
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; |
| 122 | pub const from_hex = @import("./from_hex.zig").from_hex; | 122 | pub const from_hex = @import("./from_hex.zig").from_hex; |
| 123 | pub const Pointee = @import("./Pointee.zig").Pointee; | 123 | pub const Pointee = @import("./Pointee.zig").Pointee; |
| 124 | pub const compareFnSlice = @import("./compareFnSlice.zig").compareFnSlice; | 124 | pub const compareFnSlice = @import("./compareFnSlice.zig").compareFnSlice; |
| 125 | pub const sumLen = @import("./sumLen.zig").sumLen; | ||
| 125 | 126 | ||
| 126 | test { | 127 | test { |
| 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 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const string = []const u8; | ||
| 3 | const extras = @import("./lib.zig"); | ||
| 4 | |||
| 5 | pub 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 | |||
| 11 | test { | ||
| 12 | try std.testing.expect(sumLen(u8, &.{ &.{4}, &.{3}, &.{0}, &.{9}, &.{6}, &.{7}, &.{1}, &.{2}, &.{5}, &.{8} }) == 10); | ||
| 13 | } | ||
| 14 | test { | ||
| 15 | try std.testing.expect(sumLen(u16, &.{ &.{ 8, 6 }, &.{ 7, 3 }, &.{ 2, 1 }, &.{ 5, 0 }, &.{ 9, 4 } }) == 10); | ||
| 16 | } | ||
| 17 | test { | ||
| 18 | try std.testing.expect(sumLen(u21, &.{ &.{ 5, 4, 6 }, &.{ 1, 8, 3, 2 }, &.{ 9, 0, 7 } }) == 10); | ||
| 19 | } | ||
| 20 | test { | ||
| 21 | try std.testing.expect(sumLen(u32, &.{ &.{ 3, 4 }, &.{ 5, 1, 9, 0, 6, 2, 7, 8 } }) == 10); | ||
| 22 | } | ||
| 23 | test { | ||
| 24 | try std.testing.expect(sumLen(u40, &.{ &.{ 0, 5, 6, 7, 1, 2 }, &.{ 4, 9, 3, 8 } }) == 10); | ||
| 25 | } | ||
| 26 | test { | ||
| 27 | try std.testing.expect(sumLen(u64, &.{&.{ 5, 4, 3, 9, 1, 7, 6, 2, 0, 8 }}) == 10); | ||
| 28 | } | ||