authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-18 16:34:36-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-18 16:34:36-04:00
logef0f3ba905e992556a60f935cbb7cb30cf1f27db
tree21e2b617a7cd424f82e040b94014b1c176dcf63b
parent2038f4d45a597cc672380c0a5fc8dd98e928d24c
signaturelock-open Commit is signed but in an unrecognized format.

relax std.auto_hash requirements regarding vectors

Previously, auto hash tests required vectors of different types to not hash to the same value. Now, this is allowed.

1 files changed, 6 insertions(+), 3 deletions(-)

std/hash/auto_hash.zig+6-3
...@@ -116,7 +116,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {...@@ -116,7 +116,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
116 // Otherwise, hash every element.116 // Otherwise, hash every element.
117 // TODO remove the copy to an array once field access is done.117 // TODO remove the copy to an array once field access is done.
118 const array: [info.len]info.child = key;118 const array: [info.len]info.child = key;
119 comptime var i: u32 = 0;119 comptime var i = 0;
120 inline while (i < info.len) : (i += 1) {120 inline while (i < info.len) : (i += 1) {
121 hash(hasher, array[i], strat);121 hash(hasher, array[i], strat);
122 }122 }
...@@ -357,10 +357,13 @@ test "testHash union" {...@@ -357,10 +357,13 @@ test "testHash union" {
357test "testHash vector" {357test "testHash vector" {
358 const a: @Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };358 const a: @Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };
359 const b: @Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };359 const b: @Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };
360 const c: @Vector(4, u31) = [_]u31{ 1, 2, 3, 4 };
361 testing.expect(testHash(a) == testHash(a));360 testing.expect(testHash(a) == testHash(a));
362 testing.expect(testHash(a) != testHash(b));361 testing.expect(testHash(a) != testHash(b));
363 testing.expect(testHash(a) != testHash(c));362
363 const c: @Vector(4, u31) = [_]u31{ 1, 2, 3, 4 };
364 const d: @Vector(4, u31) = [_]u31{ 1, 2, 3, 5 };
365 testing.expect(testHash(c) == testHash(c));
366 testing.expect(testHash(c) != testHash(d));
364}367}
365368
366test "testHash error union" {369test "testHash error union" {