aboutsummaryrefslogtreecommitdiff
path: root/lib/std/hash.zig
diff options
context:
space:
mode:
authorLoris Cro <kappaloris@gmail.com>2023-06-18 09:06:40 +0200
committerGitHub <noreply@github.com>2023-06-18 09:06:40 +0200
commit216ef10dc471e4db60a30208be178d6c59efeaaf (patch)
tree8c239dab283ae9cb3b7fe099bae240bcc53f894e /lib/std/hash.zig
parent0fc1d396495c1ab482197021dedac8bea3f9401c (diff)
parent729a051e9e38674233190aea23c0ac8c134f2d67 (diff)
downloadzig-216ef10dc471e4db60a30208be178d6c59efeaaf.tar.gz
zig-216ef10dc471e4db60a30208be178d6c59efeaaf.zip
Merge branch 'master' into autodoc-searchkey
Diffstat (limited to 'lib/std/hash.zig')
-rw-r--r--lib/std/hash.zig14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/std/hash.zig b/lib/std/hash.zig
index 5c85b38d55..eca7a70159 100644
--- a/lib/std/hash.zig
+++ b/lib/std/hash.zig
@@ -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;