authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-10 20:43:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:42:30-07:00
log1c7095cb7dfcba3537edf3624a61046c9b772b1f
tree36cb95ee1af69f6fe7aeb218ac69ed5c3f6ebe19
parent3ba099bfba9d3c38fe188010aa82fc589b1cabf6

add std.hash.uint32

This is handy if you have a u32 and want a u32 and don't want to take a detour through many layers of abstraction elsewhere in the std.hash namespace. Copied from https://nullprogram.com/blog/2018/07/31/

1 files changed, 14 insertions(+), 0 deletions(-)

lib/std/hash.zig+14
...@@ -36,6 +36,20 @@ const xxhash = @import("hash/xxhash.zig");...@@ -36,6 +36,20 @@ const xxhash = @import("hash/xxhash.zig");
36pub const XxHash64 = xxhash.XxHash64;36pub const XxHash64 = xxhash.XxHash64;
37pub const XxHash32 = xxhash.XxHash32;37pub const XxHash32 = xxhash.XxHash32;
3838
39/// This is handy if you have a u32 and want a u32 and don't want to take a
40/// detour through many layers of abstraction elsewhere in the std.hash
41/// namespace.
42/// Copied from https://nullprogram.com/blog/2018/07/31/
43pub fn uint32(input: u32) u32 {
44 var x: u32 = input;
45 x ^= x >> 16;
46 x *%= 0x7feb352d;
47 x ^= x >> 15;
48 x *%= 0x846ca68b;
49 x ^= x >> 16;
50 return x;
51}
52
39test {53test {
40 _ = adler;54 _ = adler;
41 _ = auto_hash;55 _ = auto_hash;