8000 Add inline murmurhash32(uint32) function. · postgres/postgres@791961f · GitHub
[go: up one dir, main page]

Skip to content {"props":{"docsUrl":"https://docs.github.com/get-started/accessibility/keyboard-shortcuts"}}

Commit 791961f

Browse files
committed
Add inline murmurhash32(uint32) function.
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
1 parent 91ad8b4 commit 791961f

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/backend/nodes/tidbitmap.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "nodes/tidbitmap.h"
4646
#include "storage/lwlock.h"
4747
#include "utils/dsa.h"
48+
#include "utils/hashutils.h"
4849

4950
/*
5051
* 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);
237238
static int tbm_shared_comparator(const void *left, const void *right,
238239
void *arg);
239240

240-
/*
241-
* Simple inline murmur hash implementation for the exact width required, for
242-
* performance.
243-
*/
244-
static inline uint32
245-
hash_blockno(BlockNumber b)
246-
{
247-
uint32 h = b;
248-
249-
h ^= h >> 16;
250-
h *= 0x85ebca6b;
251-
h ^= h >> 13;
252-
h *= 0xc2b2ae35;
253-
h ^= h >> 16;
254-
return h;
255-
}
256-
257241
/* define hashtable mapping block numbers to PagetableEntry's */
258242
#define SH_USE_NONDEFAULT_ALLOCATOR
259243
#define SH_PREFIX pagetable
260244
#define SH_ELEMENT_TYPE PagetableEntry
261245
#define SH_KEY_TYPE BlockNumber
262246
#define SH_KEY blockno
263-
#define SH_HASH_KEY(tb, key) hash_blockno(key)
247+
#define SH_HASH_KEY(tb, key) murmurhash32(key)
264248
#define SH_EQUAL(tb, a, b) a == b
265249
#define SH_SCOPE static inline
266250
#define SH_DEFINE

src/include/utils/hashutils.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,22 @@ hash_combine(uint32 a, uint32 b)
2020
return a;
2121
}
2222

23+
24+
/*
25+
* Simple inline murmur hash implementation hashing a 32 bit ingeger, for
26+
* performance.
27+
*/
28+
static inline uint32
29+
murmurhash32(uint32 data)
30+
{
31+
uint32 h = data;
32+
33+
h ^= h >> 16;
34+
h *= 0x85ebca6b;
35+
h ^= h >> 13;
36+
h *= 0xc2b2ae35;
37+
h ^= h >> 16;
38+
return h;
39+
}
40+
2341
#endif /* HASHUTILS_H */

0 commit comments

Comments
 (0)
0