mirror of
https://github.com/ziglang/zig.git
synced 2025-12-15 10:43:08 +00:00
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.
This commit is contained in:
parent
2038f4d45a
commit
ef0f3ba905
@ -116,7 +116,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
|
|||||||
// Otherwise, hash every element.
|
// Otherwise, hash every element.
|
||||||
// TODO remove the copy to an array once field access is done.
|
// TODO remove the copy to an array once field access is done.
|
||||||
const array: [info.len]info.child = key;
|
const array: [info.len]info.child = key;
|
||||||
comptime var i: u32 = 0;
|
comptime var i = 0;
|
||||||
inline while (i < info.len) : (i += 1) {
|
inline while (i < info.len) : (i += 1) {
|
||||||
hash(hasher, array[i], strat);
|
hash(hasher, array[i], strat);
|
||||||
}
|
}
|
||||||
@ -357,10 +357,13 @@ test "testHash union" {
|
|||||||
test "testHash vector" {
|
test "testHash vector" {
|
||||||
const a: @Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };
|
const a: @Vector(4, u32) = [_]u32{ 1, 2, 3, 4 };
|
||||||
const b: @Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };
|
const b: @Vector(4, u32) = [_]u32{ 1, 2, 3, 5 };
|
||||||
const c: @Vector(4, u31) = [_]u31{ 1, 2, 3, 4 };
|
|
||||||
testing.expect(testHash(a) == testHash(a));
|
testing.expect(testHash(a) == testHash(a));
|
||||||
testing.expect(testHash(a) != testHash(b));
|
testing.expect(testHash(a) != testHash(b));
|
||||||
testing.expect(testHash(a) != testHash(c));
|
|
||||||
|
const c: @Vector(4, u31) = [_]u31{ 1, 2, 3, 4 };
|
||||||
|
const d: @Vector(4, u31) = [_]u31{ 1, 2, 3, 5 };
|
||||||
|
testing.expect(testHash(c) == testHash(c));
|
||||||
|
testing.expect(testHash(c) != testHash(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "testHash error union" {
|
test "testHash error union" {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user