Skip to content

Commit 53a3a67

Browse files
authored
Fix xxhash64 to support seeds larger than u32. (#21881)
### What does this PR do? Hopefully fix #21879 ### How did you verify your code works? Added a test with a seed larger than u32. The test vector is from this tiny test I wrote to rule out upstream zig as the culprit: ```zig const std = @import("std"); const testing = std.testing; test "xxhash64 of short string with custom seed" { const input = ""; const seed: u64 = 16269921104521594740; const hash = std.hash.XxHash64.hash(seed, input); const expected_hash: u64 = 3224619365169652240; try testing.expect(hash == expected_hash); } ```
1 parent 50eaa75 commit 53a3a67

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/bun.js/api/HashObject.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub const xxHash32 = hashWrap(struct {
1313
}
1414
});
1515
pub const xxHash64 = hashWrap(struct {
16-
pub fn hash(seed: u32, bytes: []const u8) u64 {
16+
pub fn hash(seed: u64, bytes: []const u8) u64 {
1717
// sidestep .hash taking in anytype breaking ArgTuple
1818
// downstream by forcing a type signature on the input
1919
return std.hash.XxHash64.hash(seed, bytes);

test/js/bun/util/hash.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ it(`Bun.hash.xxHash64()`, () => {
4444
gcTick();
4545
expect(Bun.hash.xxHash64(new TextEncoder().encode("hello world"))).toBe(0x45ab6734b21e6968n);
4646
gcTick();
47+
// Test with seed larger than u32
48+
expect(Bun.hash.xxHash64("", 16269921104521594740n)).toBe(3224619365169652240n);
49+
gcTick();
4750
});
4851
it(`Bun.hash.xxHash3()`, () => {
4952
expect(Bun.hash.xxHash3("hello world")).toBe(0xd447b1ea40e6988bn);

0 commit comments

Comments
 (0)