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");
3636pub const XxHash64 = xxhash.XxHash64;
3737pub 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
3953test {
4054 _ = adler;
4155 _ = auto_hash;