summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Freund2017-08-22 22:36:49 +0000
committerAndres Freund2017-08-22 22:36:49 +0000
commit0052a0243d9c979a06ef273af965508103c456e0 (patch)
tree0919e3a3994c692bc763e78eb4667efa1bd4ed4e
parent2bfd1b1ee562c4e4fd065c7f7d1beaa9b9852070 (diff)
Add a hash_combine function for mixing hash values.
This hash function is derived from Boost's function of the same name. Author: Andres Freund, Thomas Munro Discussion: https://postgr.es/m/CAEepm%3D3rdgjfxW4cKvJ0OEmya2-34B0qHNG1xV0vK7TGPJGMUQ%40mail.gmail.com Discussion: https://postgr.es/m/20170731210844.3cwrkmsmbbpt4rjc%40alap3.anarazel.de
-rw-r--r--src/include/utils/hashutils.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/include/utils/hashutils.h b/src/include/utils/hashutils.h
new file mode 100644
index 0000000000..56b7bfc9cb
--- /dev/null
+++ b/src/include/utils/hashutils.h
@@ -0,0 +1,23 @@
+/*
+ * Utilities for working with hash values.
+ *
+ * Portions Copyright (c) 2017, PostgreSQL Global Development Group
+ */
+
+#ifndef HASHUTILS_H
+#define HASHUTILS_H
+
+/*
+ * Combine two hash values, resulting in another hash value, with decent bit
+ * mixing.
+ *
+ * Similar to boost's hash_combine().
+ */
+static inline uint32
+hash_combine(uint32 a, uint32 b)
+{
+ a ^= b + 0x9e3779b9 + (a << 6) + (a >> 2);
+ return a;
+}
+
+#endif /* HASHUTILS_H */