| author | |
| committer | |
| log | 410be6995e4f0e7b41174f7c0bb4bf828b758871 |
| tree | 2b252eb8529bb7cec032e58e621f34157438ef28 |
| parent | 1c148f161905469b0ad5cf4de801cf287c491174 |
Need to confirm how these fare on CI as per previous comments left which
stated OOM (on stage-1).5 files changed, 107 insertions(+), 17 deletions(-)
lib/std/hash/cityhash.zig+20-6| ... | ... | @@ -350,13 +350,27 @@ fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 { |
| 350 | 350 | const verify = @import("verify.zig"); |
| 351 | 351 | |
| 352 | 352 | test "cityhash32" { |
| 353 | // Note: SMHasher doesn't provide a 32bit version of the algorithm. | |
| 354 | // Note: The implementation was verified against the Google Abseil version. | |
| 355 | try std.testing.expectEqual(verify.smhasher(CityHash32hashIgnoreSeed), 0x68254F81); | |
| 353 | const Test = struct { | |
| 354 | fn do() !void { | |
| 355 | // SMHasher doesn't provide a 32bit version of the algorithm. | |
| 356 | // The implementation was verified against the Google Abseil version. | |
| 357 | try std.testing.expectEqual(verify.smhasher(CityHash32hashIgnoreSeed), 0x68254F81); | |
| 358 | } | |
| 359 | }; | |
| 360 | try Test.do(); | |
| 361 | @setEvalBranchQuota(75000); | |
| 362 | try comptime Test.do(); | |
| 356 | 363 | } |
| 357 | 364 | |
| 358 | 365 | test "cityhash64" { |
| 359 | // Note: This is not compliant with the SMHasher implementation of CityHash64! | |
| 360 | // Note: The implementation was verified against the Google Abseil version. | |
| 361 | try std.testing.expectEqual(verify.smhasher(CityHash64.hashWithSeed), 0x5FABC5C5); | |
| 366 | const Test = struct { | |
| 367 | fn do() !void { | |
| 368 | // This is not compliant with the SMHasher implementation of CityHash64! | |
| 369 | // The implementation was verified against the Google Abseil version. | |
| 370 | try std.testing.expectEqual(verify.smhasher(CityHash64.hashWithSeed), 0x5FABC5C5); | |
| 371 | } | |
| 372 | }; | |
| 373 | try Test.do(); | |
| 374 | @setEvalBranchQuota(75000); | |
| 375 | try comptime Test.do(); | |
| 362 | 376 | } |
lib/std/hash/murmur.zig+33-3| ... | ... | @@ -282,7 +282,6 @@ pub const Murmur3_32 = struct { |
| 282 | 282 | const verify = @import("verify.zig"); |
| 283 | 283 | |
| 284 | 284 | test "murmur2_32" { |
| 285 | try testing.expectEqual(verify.smhasher(Murmur2_32.hashWithSeed), 0x27864C1E); | |
| 286 | 285 | var v0: u32 = 0x12345678; |
| 287 | 286 | var v1: u64 = 0x1234567812345678; |
| 288 | 287 | var v0le: u32 = v0; |
| ... | ... | @@ -295,8 +294,18 @@ test "murmur2_32" { |
| 295 | 294 | try testing.expectEqual(Murmur2_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_32.hashUint64(v1)); |
| 296 | 295 | } |
| 297 | 296 | |
| 297 | test "murmur2_32 smhasher" { | |
| 298 | const Test = struct { | |
| 299 | fn do() !void { | |
| 300 | try testing.expectEqual(verify.smhasher(Murmur2_32.hashWithSeed), 0x27864C1E); | |
| 301 | } | |
| 302 | }; | |
| 303 | try Test.do(); | |
| 304 | @setEvalBranchQuota(30000); | |
| 305 | try comptime Test.do(); | |
| 306 | } | |
| 307 | ||
| 298 | 308 | test "murmur2_64" { |
| 299 | try std.testing.expectEqual(verify.smhasher(Murmur2_64.hashWithSeed), 0x1F0D3804); | |
| 300 | 309 | var v0: u32 = 0x12345678; |
| 301 | 310 | var v1: u64 = 0x1234567812345678; |
| 302 | 311 | var v0le: u32 = v0; |
| ... | ... | @@ -309,8 +318,18 @@ test "murmur2_64" { |
| 309 | 318 | try testing.expectEqual(Murmur2_64.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur2_64.hashUint64(v1)); |
| 310 | 319 | } |
| 311 | 320 | |
| 321 | test "mumur2_64 smhasher" { | |
| 322 | const Test = struct { | |
| 323 | fn do() !void { | |
| 324 | try std.testing.expectEqual(verify.smhasher(Murmur2_64.hashWithSeed), 0x1F0D3804); | |
| 325 | } | |
| 326 | }; | |
| 327 | try Test.do(); | |
| 328 | @setEvalBranchQuota(30000); | |
| 329 | try comptime Test.do(); | |
| 330 | } | |
| 331 | ||
| 312 | 332 | test "murmur3_32" { |
| 313 | try std.testing.expectEqual(verify.smhasher(Murmur3_32.hashWithSeed), 0xB0F57EE3); | |
| 314 | 333 | var v0: u32 = 0x12345678; |
| 315 | 334 | var v1: u64 = 0x1234567812345678; |
| 316 | 335 | var v0le: u32 = v0; |
| ... | ... | @@ -322,3 +341,14 @@ test "murmur3_32" { |
| 322 | 341 | try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v0le))[0..4]), Murmur3_32.hashUint32(v0)); |
| 323 | 342 | try testing.expectEqual(Murmur3_32.hash(@as([*]u8, @ptrCast(&v1le))[0..8]), Murmur3_32.hashUint64(v1)); |
| 324 | 343 | } |
| 344 | ||
| 345 | test "mumur3_32 smhasher" { | |
| 346 | const Test = struct { | |
| 347 | fn do() !void { | |
| 348 | try std.testing.expectEqual(verify.smhasher(Murmur3_32.hashWithSeed), 0xB0F57EE3); | |
| 349 | } | |
| 350 | }; | |
| 351 | try Test.do(); | |
| 352 | @setEvalBranchQuota(30000); | |
| 353 | try comptime Test.do(); | |
| 354 | } |
lib/std/hash/verify.zig+1-1| ... | ... | @@ -22,7 +22,7 @@ fn initMaybeSeed(comptime Hash: anytype, seed: anytype) Hash { |
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | // Returns a verification code, the same as user by SMHasher. | |
| 25 | // Returns a verification code, the same as used by SMHasher. | |
| 26 | 26 | // |
| 27 | 27 | // Hash keys of the form {0}, {0,1}, {0,1,2}... up to N=255, using 256-N as seed. |
| 28 | 28 | // First four-bytes of the hash, interpreted as little-endian is the verification code. |
lib/std/hash/wyhash.zig+17-3| ... | ... | @@ -66,7 +66,7 @@ pub const Wyhash = struct { |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | pub fn final(self: *Wyhash) u64 { |
| 69 | var input = self.buf[0..self.buf_len]; | |
| 69 | var input: []const u8 = self.buf[0..self.buf_len]; | |
| 70 | 70 | var newSelf = self.shallowCopy(); // ensure idempotency |
| 71 | 71 | |
| 72 | 72 | if (self.total_len <= 16) { |
| ... | ... | @@ -231,11 +231,25 @@ test "test vectors at comptime" { |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | test "smhasher" { |
| 234 | try expectEqual(verify.smhasher(Wyhash.hash), 0xBD5E840C); | |
| 234 | const Test = struct { | |
| 235 | fn do() !void { | |
| 236 | try expectEqual(verify.smhasher(Wyhash.hash), 0xBD5E840C); | |
| 237 | } | |
| 238 | }; | |
| 239 | try Test.do(); | |
| 240 | @setEvalBranchQuota(50000); | |
| 241 | try comptime Test.do(); | |
| 235 | 242 | } |
| 236 | 243 | |
| 237 | 244 | test "iterative api" { |
| 238 | try verify.iterativeApi(Wyhash); | |
| 245 | const Test = struct { | |
| 246 | fn do() !void { | |
| 247 | try verify.iterativeApi(Wyhash); | |
| 248 | } | |
| 249 | }; | |
| 250 | try Test.do(); | |
| 251 | @setEvalBranchQuota(50000); | |
| 252 | try comptime Test.do(); | |
| 239 | 253 | } |
| 240 | 254 | |
| 241 | 255 | test "iterative maintains last sixteen" { |
lib/std/hash/xxhash.zig+36-4| ... | ... | @@ -457,12 +457,28 @@ test "xxhash64" { |
| 457 | 457 | try testExpect(H, 0, "abcdefghijklmnopqrstuvwxyz", 0xcfe1f278fa89835c); |
| 458 | 458 | try testExpect(H, 0, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 0xaaa46907d3047814); |
| 459 | 459 | try testExpect(H, 0, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", 0xe04a477f19ee145d); |
| 460 | } | |
| 460 | 461 | |
| 461 | try expectEqual(verify.smhasher(H.hash), 0x024B7CF4); | |
| 462 | test "xxhash64 smhasher" { | |
| 463 | const Test = struct { | |
| 464 | fn do() !void { | |
| 465 | try expectEqual(verify.smhasher(XxHash64.hash), 0x024B7CF4); | |
| 466 | } | |
| 467 | }; | |
| 468 | try Test.do(); | |
| 469 | @setEvalBranchQuota(75000); | |
| 470 | comptime try Test.do(); | |
| 462 | 471 | } |
| 463 | 472 | |
| 464 | 473 | test "xxhash64 iterative api" { |
| 465 | try verify.iterativeApi(XxHash64); | |
| 474 | const Test = struct { | |
| 475 | fn do() !void { | |
| 476 | try verify.iterativeApi(XxHash64); | |
| 477 | } | |
| 478 | }; | |
| 479 | try Test.do(); | |
| 480 | @setEvalBranchQuota(30000); | |
| 481 | comptime try Test.do(); | |
| 466 | 482 | } |
| 467 | 483 | |
| 468 | 484 | test "xxhash32" { |
| ... | ... | @@ -475,10 +491,26 @@ test "xxhash32" { |
| 475 | 491 | try testExpect(H, 0, "abcdefghijklmnopqrstuvwxyz", 0x63a14d5f); |
| 476 | 492 | try testExpect(H, 0, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 0x9c285e64); |
| 477 | 493 | try testExpect(H, 0, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", 0x9c05f475); |
| 494 | } | |
| 478 | 495 | |
| 479 | try expectEqual(verify.smhasher(H.hash), 0xBA88B743); | |
| 496 | test "xxhash32 smhasher" { | |
| 497 | const Test = struct { | |
| 498 | fn do() !void { | |
| 499 | try expectEqual(verify.smhasher(XxHash32.hash), 0xBA88B743); | |
| 500 | } | |
| 501 | }; | |
| 502 | try Test.do(); | |
| 503 | @setEvalBranchQuota(75000); | |
| 504 | comptime try Test.do(); | |
| 480 | 505 | } |
| 481 | 506 | |
| 482 | 507 | test "xxhash32 iterative api" { |
| 483 | try verify.iterativeApi(XxHash32); | |
| 508 | const Test = struct { | |
| 509 | fn do() !void { | |
| 510 | try verify.iterativeApi(XxHash32); | |
| 511 | } | |
| 512 | }; | |
| 513 | try Test.do(); | |
| 514 | @setEvalBranchQuota(30000); | |
| 515 | comptime try Test.do(); | |
| 484 | 516 | } |