| ... | ... | @@ -30,13 +30,15 @@ pub fn hashPointer(hasher: anytype, key: anytype, comptime strat: HashStrategy) |
| 30 | 30 | .DeepRecursive => hash(hasher, key.*, .DeepRecursive), |
| 31 | 31 | }, |
| 32 | 32 | |
| 33 | | .Slice => switch (strat) { |
| 34 | | .Shallow => { |
| 35 | | hashPointer(hasher, key.ptr, .Shallow); |
| 36 | | hash(hasher, key.len, .Shallow); |
| 37 | | }, |
| 38 | | .Deep => hashArray(hasher, key, .Shallow), |
| 39 | | .DeepRecursive => hashArray(hasher, key, .DeepRecursive), |
| 33 | .Slice => { |
| 34 | switch (strat) { |
| 35 | .Shallow => { |
| 36 | hashPointer(hasher, key.ptr, .Shallow); |
| 37 | }, |
| 38 | .Deep => hashArray(hasher, key, .Shallow), |
| 39 | .DeepRecursive => hashArray(hasher, key, .DeepRecursive), |
| 40 | } |
| 41 | hash(hasher, key.len, .Shallow); |
| 40 | 42 | }, |
| 41 | 43 | |
| 42 | 44 | .Many, |
| ... | ... | @@ -53,17 +55,8 @@ pub fn hashPointer(hasher: anytype, key: anytype, comptime strat: HashStrategy) |
| 53 | 55 | |
| 54 | 56 | /// Helper function to hash a set of contiguous objects, from an array or slice. |
| 55 | 57 | pub fn hashArray(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { |
| 56 | | switch (strat) { |
| 57 | | .Shallow => { |
| 58 | | for (key) |element| { |
| 59 | | hash(hasher, element, .Shallow); |
| 60 | | } |
| 61 | | }, |
| 62 | | else => { |
| 63 | | for (key) |element| { |
| 64 | | hash(hasher, element, strat); |
| 65 | | } |
| 66 | | }, |
| 58 | for (key) |element| { |
| 59 | hash(hasher, element, strat); |
| 67 | 60 | } |
| 68 | 61 | } |
| 69 | 62 | |
| ... | ... | @@ -359,6 +352,12 @@ test "testHash array" { |
| 359 | 352 | try testing.expectEqual(h, hasher.final()); |
| 360 | 353 | } |
| 361 | 354 | |
| 355 | test "testHash multi-dimensional array" { |
| 356 | const a = [_][]const u32{ &.{ 1, 2, 3 }, &.{ 4, 5 } }; |
| 357 | const b = [_][]const u32{ &.{ 1, 2 }, &.{ 3, 4, 5 } }; |
| 358 | try testing.expect(testHash(a) != testHash(b)); |
| 359 | } |
| 360 | |
| 362 | 361 | test "testHash struct" { |
| 363 | 362 | const Foo = struct { |
| 364 | 363 | a: u32 = 1, |