@@ -273,6 +273,8 @@ static void hdefault(HTAB *hashp);
273
273
static int choose_nelem_alloc (Size entrysize );
274
274
static bool init_htab (HTAB * hashp , long nelem );
275
275
static void hash_corrupted (HTAB * hashp );
276
+ static uint32 hash_initial_lookup (HTAB * hashp , uint32 hashvalue ,
277
+ HASHBUCKET * * bucketptr );
276
278
static long next_pow2_long (long num );
277
279
static int next_pow2_int (long num );
278
280
static void register_seq_scan (HTAB * hashp );
@@ -972,10 +974,6 @@ hash_search_with_hash_value(HTAB *hashp,
972
974
HASHHDR * hctl = hashp -> hctl ;
973
975
int freelist_idx = FREELIST_IDX (hctl , hashvalue );
974
976
Size keysize ;
975
- uint32 bucket ;
976
- long segment_num ;
977
- long segment_ndx ;
978
- HASHSEGMENT segp ;
979
977
HASHBUCKET currBucket ;
980
978
HASHBUCKET * prevBucketPtr ;
981
979
HashCompareFunc match ;
@@ -1008,17 +1006,7 @@ hash_search_with_hash_value(HTAB *hashp,
1008
1006
/*
1009
1007
* Do the initial lookup
1010
1008
*/
1011
- bucket = calc_bucket (hctl , hashvalue );
1012
-
1013
- segment_num = bucket >> hashp -> sshift ;
1014
- segment_ndx = MOD (bucket , hashp -> ssize );
1015
-
1016
- segp = hashp -> dir [segment_num ];
1017
-
1018
- if (segp == NULL )
1019
- hash_corrupted (hashp );
1020
-
1021
- prevBucketPtr = & segp [segment_ndx ];
1009
+ (void ) hash_initial_lookup (hashp , hashvalue , & prevBucketPtr );
1022
1010
currBucket = * prevBucketPtr ;
1023
1011
1024
1012
/*
@@ -1159,14 +1147,10 @@ hash_update_hash_key(HTAB *hashp,
1159
1147
const void * newKeyPtr )
1160
1148
{
1161
1149
HASHELEMENT * existingElement = ELEMENT_FROM_KEY (existingEntry );
1162
- HASHHDR * hctl = hashp -> hctl ;
1163
1150
uint32 newhashvalue ;
1164
1151
Size keysize ;
1165
1152
uint32 bucket ;
1166
1153
uint32 newbucket ;
1167
- long segment_num ;
1168
- long segment_ndx ;
1169
- HASHSEGMENT segp ;
1170
1154
HASHBUCKET currBucket ;
1171
1155
HASHBUCKET * prevBucketPtr ;
1172
1156
HASHBUCKET * oldPrevPtr ;
@@ -1187,17 +1171,8 @@ hash_update_hash_key(HTAB *hashp,
1187
1171
* this to be able to unlink it from its hash chain, but as a side benefit
1188
1172
* we can verify the validity of the passed existingEntry pointer.
1189
1173
*/
1190
- bucket = calc_bucket (hctl , existingElement -> hashvalue );
1191
-
1192
- segment_num = bucket >> hashp -> sshift ;
1193
- segment_ndx = MOD (bucket , hashp -> ssize );
1194
-
1195
- segp = hashp -> dir [segment_num ];
1196
-
1197
- if (segp == NULL )
1198
- hash_corrupted (hashp );
1199
-
1200
- prevBucketPtr = & segp [segment_ndx ];
1174
+ bucket = hash_initial_lookup (hashp , existingElement -> hashvalue ,
1175
+ & prevBucketPtr );
1201
1176
currBucket = * prevBucketPtr ;
1202
1177
1203
1178
while (currBucket != NULL )
@@ -1219,18 +1194,7 @@ hash_update_hash_key(HTAB *hashp,
1219
1194
* chain we want to put the entry into.
1220
1195
*/
1221
1196
newhashvalue = hashp -> hash (newKeyPtr , hashp -> keysize );
1222
-
1223
- newbucket = calc_bucket (hctl , newhashvalue );
1224
-
1225
- segment_num = newbucket >> hashp -> sshift ;
1226
- segment_ndx = MOD (newbucket , hashp -> ssize );
1227
-
1228
- segp = hashp -> dir [segment_num ];
1229
-
1230
- if (segp == NULL )
1231
- hash_corrupted (hashp );
1232
-
1233
- prevBucketPtr = & segp [segment_ndx ];
1197
+ newbucket = hash_initial_lookup (hashp , newhashvalue , & prevBucketPtr );
1234
1198
currBucket = * prevBucketPtr ;
1235
1199
1236
1200
/*
@@ -1741,6 +1705,33 @@ element_alloc(HTAB *hashp, int nelem, int freelist_idx)
1741
1705
return true;
1742
1706
}
1743
1707
1708
+ /*
1709
+ * Do initial lookup of a bucket for the given hash value, retrieving its
1710
+ * bucket number and its hash bucket.
1711
+ */
1712
+ static inline uint32
1713
+ hash_initial_lookup (HTAB * hashp , uint32 hashvalue , HASHBUCKET * * bucketptr )
1714
+ {
1715
+ HASHHDR * hctl = hashp -> hctl ;
1716
+ HASHSEGMENT segp ;
1717
+ long segment_num ;
1718
+ long segment_ndx ;
1719
+ uint32 bucket ;
1720
+
1721
+ bucket = calc_bucket (hctl , hashvalue );
1722
+
1723
+ segment_num = bucket >> hashp -> sshift ;
1724
+ segment_ndx = MOD (bucket , hashp -> ssize );
1725
+
1726
+ segp = hashp -> dir [segment_num ];
1727
+
1728
+ if (segp == NULL )
1729
+ hash_corrupted (hashp );
1730
+
1731
+ * bucketptr = & segp [segment_ndx ];
1732
+ return bucket ;
1733
+ }
1734
+
1744
1735
/* complain when we have detected a corrupted hashtable */
1745
1736
static void
1746
1737
hash_corrupted (HTAB * hashp )
0 commit comments