mirror of
https://github.com/ziglang/zig.git
synced 2026-02-17 14:59:14 +00:00
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/
This commit is contained in:
parent
3ba099bfba
commit
1c7095cb7d
@ -36,6 +36,20 @@ const xxhash = @import("hash/xxhash.zig");
|
||||
pub const XxHash64 = xxhash.XxHash64;
|
||||
pub const XxHash32 = xxhash.XxHash32;
|
||||
|
||||
/// 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/
|
||||
pub fn uint32(input: u32) u32 {
|
||||
var x: u32 = input;
|
||||
x ^= x >> 16;
|
||||
x *%= 0x7feb352d;
|
||||
x ^= x >> 15;
|
||||
x *%= 0x846ca68b;
|
||||
x ^= x >> 16;
|
||||
return x;
|
||||
}
|
||||
|
||||
test {
|
||||
_ = adler;
|
||||
_ = auto_hash;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user