File tree Expand file tree Collapse file tree 2 files changed +33
-6
lines changed Expand file tree Collapse file tree 2 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -206,15 +206,27 @@ static void ReleaseAuxProcessResourcesCallback(int code, Datum arg);
206
206
* INTERNAL ROUTINES *
207
207
*****************************************************************************/
208
208
209
+ /*
210
+ * Hash function for value+kind combination.
211
+ */
209
212
static inline uint32
210
213
hash_resource_elem (Datum value , const ResourceOwnerDesc * kind )
211
214
{
212
- Datum data [2 ];
213
-
214
- data [0 ] = value ;
215
- data [1 ] = PointerGetDatum (kind );
216
-
217
- return hash_bytes ((unsigned char * ) & data , 2 * SIZEOF_DATUM );
215
+ /*
216
+ * Most resource kinds store a pointer in 'value', and pointers are unique
217
+ * all on their own. But some resources store plain integers (Files and
218
+ * Buffers as of this writing), so we want to incorporate the 'kind' in
219
+ * the hash too, otherwise those resources will collide a lot. But
220
+ * because there are only a few resource kinds like that - and only a few
221
+ * resource kinds to begin with - we don't need to work too hard to mix
222
+ * 'kind' into the hash. Just add it with hash_combine(), it perturbs the
223
+ * result enough for our purposes.
224
+ */
225
+ #if SIZEOF_DATUM == 8
226
+ return hash_combine64 (murmurhash64 ((uint64 ) value ), (uint64 ) kind );
227
+ #else
228
+ return hash_combine (murmurhash32 ((uint32 ) value ), (uint32 ) kind );
229
+ #endif
218
230
}
219
231
220
232
/*
Original file line number Diff line number Diff line change @@ -101,4 +101,19 @@ murmurhash32(uint32 data)
101
101
return h ;
102
102
}
103
103
104
+ /* 64-bit variant */
105
+ static inline uint64
106
+ murmurhash64 (uint64 data )
107
+ {
108
+ uint64 h = data ;
109
+
110
+ h ^= h >> 33 ;
111
+ h *= 0xff51afd7ed558ccd ;
112
+ h ^= h >> 33 ;
113
+ h *= 0xc4ceb9fe1a85ec53 ;
114
+ h ^= h >> 33 ;
115
+
116
+ return h ;
117
+ }
118
+
104
119
#endif /* HASHFN_H */
You can’t perform that action at this time.
0 commit comments