]> granicus.if.org Git - postgresql/commitdiff
Backport: Add inline murmurhash32(uint32) function.
authorAndres Freund <andres@anarazel.de>
Fri, 22 Sep 2017 20:38:42 +0000 (13:38 -0700)
committerAndres Freund <andres@anarazel.de>
Mon, 29 Jan 2018 19:24:57 +0000 (11:24 -0800)
The function already existed in tidbitmap.c but more users requiring
fast hashing of 32bit ints are coming up.

Author: Andres Freund
Discussion:
    https://postgr.es/m/20170914061207.zxotvyopetm7lrrp@alap3.anarazel.de
    https://postgr.es/m/15ae5ae2-bc74-ebef-f9d6-34b16423cc04@blackducksoftware.com
Original-Commit: 791961f59b792fbd4f0a992d3ccab47298e79103

src/backend/nodes/tidbitmap.c
src/include/utils/hashutils.h [new file with mode: 0644]

index c4e53adb0ca77022aa8954a1333006b17b65de7b..01d6bc5c11856cf7e7efd60fcb4d6f7db5a59f2e 100644 (file)
@@ -45,6 +45,7 @@
 #include "nodes/tidbitmap.h"
 #include "storage/lwlock.h"
 #include "utils/dsa.h"
+#include "utils/hashutils.h"
 
 /*
  * The maximum number of tuples per page is not large (typically 256 with
@@ -237,30 +238,13 @@ static int        tbm_comparator(const void *left, const void *right);
 static int tbm_shared_comparator(const void *left, const void *right,
                                          void *arg);
 
-/*
- * Simple inline murmur hash implementation for the exact width required, for
- * performance.
- */
-static inline uint32
-hash_blockno(BlockNumber b)
-{
-       uint32          h = b;
-
-       h ^= h >> 16;
-       h *= 0x85ebca6b;
-       h ^= h >> 13;
-       h *= 0xc2b2ae35;
-       h ^= h >> 16;
-       return h;
-}
-
 /* define hashtable mapping block numbers to PagetableEntry's */
 #define SH_USE_NONDEFAULT_ALLOCATOR
 #define SH_PREFIX pagetable
 #define SH_ELEMENT_TYPE PagetableEntry
 #define SH_KEY_TYPE BlockNumber
 #define SH_KEY blockno
-#define SH_HASH_KEY(tb, key) hash_blockno(key)
+#define SH_HASH_KEY(tb, key) murmurhash32(key)
 #define SH_EQUAL(tb, a, b) a == b
 #define SH_SCOPE static inline
 #define SH_DEFINE
diff --git a/src/include/utils/hashutils.h b/src/include/utils/hashutils.h
new file mode 100644 (file)
index 0000000..636d332
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Utilities for working with hash values.
+ *
+ * Portions Copyright (c) 2017, PostgreSQL Global Development Group
+ */
+
+#ifndef HASHUTILS_H
+#define HASHUTILS_H
+
+/*
+ * Simple inline murmur hash implementation hashing a 32 bit ingeger, for
+ * performance.
+ */
+static inline uint32
+murmurhash32(uint32 data)
+{
+       uint32          h = data;
+
+       h ^= h >> 16;
+       h *= 0x85ebca6b;
+       h ^= h >> 13;
+       h *= 0xc2b2ae35;
+       h ^= h >> 16;
+       return h;
+}
+
+#endif                                                 /* HASHUTILS_H */